mirror of
https://github.com/wassname/ray.git
synced 2026-08-05 13:21:03 +08:00
Add ray.is_initialized() function. (#2818)
* Add ray.is_initialized() function. * Add assert.
This commit is contained in:
committed by
Philipp Moritz
parent
e7db54bdb0
commit
3f6ed537a4
@@ -3,6 +3,8 @@ The Ray API
|
||||
|
||||
.. autofunction:: ray.init
|
||||
|
||||
.. autofunction:: ray.is_initialized
|
||||
|
||||
.. autofunction:: ray.remote
|
||||
|
||||
.. autofunction:: ray.get
|
||||
|
||||
@@ -50,7 +50,8 @@ from ray.local_scheduler import ObjectID, _config # noqa: E402
|
||||
from ray.profiling import profile # noqa: E402
|
||||
from ray.worker import (error_info, init, connect, disconnect, get, put, wait,
|
||||
remote, get_gpu_ids, get_resource_ids, get_webui_url,
|
||||
register_custom_serializer, shutdown) # noqa: E402
|
||||
register_custom_serializer, shutdown,
|
||||
is_initialized) # noqa: E402
|
||||
from ray.worker import (SCRIPT_MODE, WORKER_MODE, LOCAL_MODE,
|
||||
PYTHON_MODE) # noqa: E402
|
||||
from ray.worker import global_state # noqa: E402
|
||||
@@ -67,9 +68,10 @@ __version__ = "0.5.2"
|
||||
__all__ = [
|
||||
"error_info", "init", "connect", "disconnect", "get", "put", "wait",
|
||||
"remote", "profile", "actor", "method", "get_gpu_ids", "get_resource_ids",
|
||||
"get_webui_url", "register_custom_serializer", "shutdown", "SCRIPT_MODE",
|
||||
"WORKER_MODE", "LOCAL_MODE", "PYTHON_MODE", "global_state", "ObjectID",
|
||||
"_config", "__version__", "internal"
|
||||
"get_webui_url", "register_custom_serializer", "shutdown",
|
||||
"is_initialized", "SCRIPT_MODE", "WORKER_MODE", "LOCAL_MODE",
|
||||
"PYTHON_MODE", "global_state", "ObjectID", "_config", "__version__",
|
||||
"internal"
|
||||
]
|
||||
|
||||
import ctypes # noqa: E402
|
||||
|
||||
@@ -1987,6 +1987,15 @@ def print_error_messages_raylet(worker):
|
||||
pass
|
||||
|
||||
|
||||
def is_initialized():
|
||||
"""Check if ray.init has been called yet.
|
||||
|
||||
Returns:
|
||||
True if ray.init has already been called and false otherwise.
|
||||
"""
|
||||
return ray.worker.global_worker.connected
|
||||
|
||||
|
||||
def print_error_messages(worker):
|
||||
"""Print error messages in the background on the driver.
|
||||
|
||||
|
||||
@@ -2536,5 +2536,21 @@ class GlobalStateAPI(unittest.TestCase):
|
||||
ray.experimental.flush_evicted_objects_unsafe()
|
||||
|
||||
|
||||
class InitializationTest(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
ray.shutdown()
|
||||
assert not ray.is_initialized()
|
||||
|
||||
def testInitialized(self):
|
||||
assert not ray.is_initialized()
|
||||
ray.init(num_cpus=0)
|
||||
assert ray.is_initialized()
|
||||
|
||||
def testInitializedLocalMode(self):
|
||||
assert not ray.is_initialized()
|
||||
ray.init(num_cpus=0, local_mode=True)
|
||||
assert ray.is_initialized()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
|
||||
Reference in New Issue
Block a user