MCPcopy
hub / github.com/ray-project/ray / get_runtime_context

Function get_runtime_context

python/ray/runtime_context.py:641–667  ·  view source on GitHub ↗

Get the runtime context of the current driver/worker. The obtained runtime context can be used to get the metadata of the current driver, task, or actor. Example: .. testcode:: import ray # Get the job id. ray.get_runtime_context().get_job_

()

Source from the content-addressed store, hash-verified

639@PublicAPI
640@client_mode_hook
641def get_runtime_context() -> RuntimeContext:
642 """Get the runtime context of the current driver/worker.
643
644 The obtained runtime context can be used to get the metadata
645 of the current driver, task, or actor.
646
647 Example:
648
649 .. testcode::
650
651 import ray
652 # Get the job id.
653 ray.get_runtime_context().get_job_id()
654 # Get the session name (used as SessionName label in Ray metrics).
655 ray.get_runtime_context().get_session_name()
656 # Get the actor id.
657 ray.get_runtime_context().get_actor_id()
658 # Get the task id.
659 ray.get_runtime_context().get_task_id()
660
661 """
662 with _runtime_context_lock:
663 global _runtime_context
664 if _runtime_context is None:
665 _runtime_context = RuntimeContext(ray._private.worker.global_worker)
666
667 return _runtime_context

Calls 1

RuntimeContextClass · 0.70

Used in the wild real call sites across dependent graphs

searching dependent graphs…