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

Class RuntimeContext

python/ray/runtime_context.py:17–632  ·  view source on GitHub ↗

A class used for getting runtime context.

Source from the content-addressed store, hash-verified

15
16@PublicAPI
17class RuntimeContext(object):
18 """A class used for getting runtime context."""
19
20 def __init__(self, worker):
21 assert worker is not None
22 self.worker = worker
23
24 @Deprecated(
25 message="Use get_xxx_id() methods to get relevant ids instead", warning=True
26 )
27 def get(self) -> Dict[str, Any]:
28 """Get a dictionary of the current context.
29
30 Returns:
31 dict: Dictionary of the current context.
32 """
33 context = {
34 "job_id": self.job_id,
35 "node_id": self.node_id,
36 "namespace": self.namespace,
37 }
38 if self.worker.mode == ray._private.worker.WORKER_MODE:
39 if self.task_id is not None:
40 context["task_id"] = self.task_id
41 if self.actor_id is not None:
42 context["actor_id"] = self.actor_id
43
44 return context
45
46 @property
47 @Deprecated(message="Use get_job_id() instead", warning=True)
48 def job_id(self):
49 """Get current job ID for this worker or driver.
50
51 Job ID is the id of your Ray drivers that create tasks or actors.
52
53 Returns:
54 If called by a driver, this returns the job ID. If called in
55 a task, return the job ID of the associated driver.
56
57 """
58 job_id = self.worker.current_job_id
59 assert not job_id.is_nil()
60 return job_id
61
62 def get_job_id(self) -> str:
63 """Get current job ID for this worker or driver.
64
65 Job ID is the id of your Ray drivers that create tasks or actors.
66
67 Returns:
68 If called by a driver, this returns the job ID. If called in
69 a task, return the job ID of the associated driver. The
70 job ID will be hex format.
71
72 Raises:
73 RuntimeError: If Ray has not been initialized.
74 """

Callers 2

build_runtime_contextMethod · 0.90
get_runtime_contextFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…