diff --git a/python/ray/runtime_context.py b/python/ray/runtime_context.py index 2dfff96eb3f5f..64bee3fc7cf79 100644 --- a/python/ray/runtime_context.py +++ b/python/ray/runtime_context.py @@ -189,7 +189,7 @@ def _get_actor_call_stats(self): @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 66c7df1fc7e41..8ce983da2085a 100644 --- a/python/ray/tests/test_runtime_context.py +++ b/python/ray/tests/test_runtime_context.py @@ -220,6 +220,14 @@ async def func(self): 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__]))