From fe413c3c5eef400a03a8e5407b295eb122f0b244 Mon Sep 17 00:00:00 2001 From: mwtian <81660174+mwtian@users.noreply.github.com> Date: Wed, 6 Oct 2021 20:20:47 -0700 Subject: [PATCH] [Client] disable auto init for get_runtime_context() (#19127) --- python/ray/runtime_context.py | 2 +- python/ray/tests/test_runtime_context.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/python/ray/runtime_context.py b/python/ray/runtime_context.py index 2dfff96eb..64bee3fc7 100644 --- a/python/ray/runtime_context.py +++ b/python/ray/runtime_context.py @@ -189,7 +189,7 @@ _runtime_context = None @PublicAPI(stability="beta") -@client_mode_hook(auto_init=True) +@client_mode_hook(auto_init=False) def get_runtime_context(): """Get the runtime context of the current driver/worker. diff --git a/python/ray/tests/test_runtime_context.py b/python/ray/tests/test_runtime_context.py index 66c7df1fc..8ce983da2 100644 --- a/python/ray/tests/test_runtime_context.py +++ b/python/ray/tests/test_runtime_context.py @@ -220,6 +220,14 @@ def test_actor_stats_async_actor(ray_start_regular): assert max(result["AysncActor.func"]["pending"] for result in results) == 3 +# get_runtime_context() can be called outside of Ray so it should not start +# Ray automatically. +def test_no_auto_init(shutdown_only): + assert not ray.is_initialized() + ray.get_runtime_context() + assert not ray.is_initialized() + + if __name__ == "__main__": import pytest sys.exit(pytest.main(["-v", __file__]))