Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion python/ray/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def f():
ray.get(bar.remote(*[f() for _ in range(200)]))


def test_default_worker_import_dependency():
def test_default_worker_import_dependency(shutdown_only):
"""
Test ray's python worker import doesn't import the not-allowed dependencies.
"""
Expand All @@ -129,6 +129,11 @@ def test_default_worker_import_dependency():
# See https://github.com/ray-project/ray/issues/33891
blocked_deps = ["numpy"]

# Ray should not be importing pydantic (used in serialization) eagerly.
# This introduces regression in worker start up time.
# https://github.com/ray-project/ray/issues/41338
blocked_deps += ["pydantic"]

# Remove the ray module and the blocked deps from sys.modules.
sys.modules.pop("ray", None)
assert "ray" not in sys.modules
Expand All @@ -146,6 +151,19 @@ def test_default_worker_import_dependency():
for dep in blocked_deps:
assert dep not in sys.modules

# Test starting a ray workers should not see unwanted deps loaded eagerly.
ray.init()

@ray.remote
def f():
import ray # noqa: F401

assert "ray" in sys.modules
for x in blocked_deps:
assert x not in sys.modules
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test it failed the test on master.


ray.get(f.remote())


# https://github.com/ray-project/ray/issues/7287
def test_omp_threads_set(ray_start_cluster, monkeypatch):
Expand Down
3 changes: 2 additions & 1 deletion python/ray/util/serialization_addons.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import sys

from ray.util.annotations import DeveloperAPI
from ray._private.pydantic_compat import register_pydantic_serializers


@DeveloperAPI
Expand All @@ -27,6 +26,8 @@ def register_starlette_serializer(serialization_context):

@DeveloperAPI
def apply(serialization_context):
from ray._private.pydantic_compat import register_pydantic_serializers

register_pydantic_serializers(serialization_context)
register_starlette_serializer(serialization_context)

Expand Down