ray.runtime_context.RuntimeContext#

class ray.runtime_context.RuntimeContext(worker)[source]#

Bases: object

A class used for getting runtime context.

PublicAPI: This API is stable across Ray releases.

get() Dict[str, Any][source]#

Get a dictionary of the current context.

Returns

Dictionary of the current context.

Return type

dict

property job_id#

Get current job ID for this worker or driver.

Job ID is the id of your Ray drivers that create tasks or actors.

Returns

If called by a driver, this returns the job ID. If called in a task, return the job ID of the associated driver.

Warning

DEPRECATED: This API is deprecated and may be removed in future Ray releases. Use get_job_id() instead

get_job_id() str[source]#

Get current job ID for this worker or driver.

Job ID is the id of your Ray drivers that create tasks or actors.

Returns

If called by a driver, this returns the job ID. If called in a task, return the job ID of the associated driver. The job ID will be hex format.

Raises

AssertionError – If not called in a driver or worker. Generally, this means that ray.init() was not called.

property node_id#

Get current node ID for this worker or driver.

Node ID is the id of a node that your driver, task, or actor runs.

Returns

A node id for this worker or driver.

Warning

DEPRECATED: This API is deprecated and may be removed in future Ray releases. Use get_node_id() instead

get_node_id() str[source]#

Get current node ID for this worker or driver.

Node ID is the id of a node that your driver, task, or actor runs. The ID will be in hex format.

Returns

A node id in hex format for this worker or driver.

Raises

AssertionError – If not called in a driver or worker. Generally, this means that ray.init() was not called.

property task_id#

Get current task ID for this worker or driver.

Task ID is the id of a Ray task. This shouldn’t be used in a driver process.

Example

>>> import ray
>>> @ray.remote
... class Actor:
...     def ready(self):
...         return True
>>>
>>> @ray.remote 
... def f():
...     return True
>>> # All the below code will generate different task ids.
>>> # Task ids are available for actor creation.
>>> a = Actor.remote() 
>>> # Task ids are available for actor tasks.
>>> a.ready.remote() 
>>> # Task ids are available for normal tasks.
>>> f.remote() 
Returns

The current worker’s task id. None if there’s no task id.

Warning

DEPRECATED: This API is deprecated and may be removed in future Ray releases. Use get_task_id() instead

get_task_id() Optional[str][source]#

Get current task ID for this worker or driver.

Task ID is the id of a Ray task. The ID will be in hex format. This shouldn’t be used in a driver process.

Example

>>> import ray
>>> @ray.remote
... class Actor:
...     def ready(self):
...         return True
>>>
>>> @ray.remote 
... def f():
...     return True
>>> # All the below code will generate different task ids.
>>> # Task ids are available for actor creation.
>>> a = Actor.remote() 
>>> # Task ids are available for actor tasks.
>>> a.ready.remote() 
>>> # Task ids are available for normal tasks.
>>> f.remote() 
Returns

The current worker’s task id in hex. None if there’s no task id.

property actor_id#

Get the current actor ID in this worker.

ID of the actor of the current process. This shouldn’t be used in a driver process.

Returns

The current actor id in this worker. None if there’s no actor id.

Warning

DEPRECATED: This API is deprecated and may be removed in future Ray releases. Use get_actor_id() instead

get_actor_id() Optional[str][source]#

Get the current actor ID in this worker.

ID of the actor of the current process. This shouldn’t be used in a driver process. The ID will be in hex format.

Returns

The current actor id in hex format in this worker. None if there’s no actor id.

property namespace#

Get the current namespace of this worker.

Returns

The current namespace of this worker.

property was_current_actor_reconstructed#

Check whether this actor has been restarted.

Returns

Whether this actor has been ever restarted.

property current_placement_group_id#

Get the current Placement group ID of this worker.

Returns

The current placement group id of this worker.

Warning

DEPRECATED: This API is deprecated and may be removed in future Ray releases. Use get_placement_group_id() instead

get_placement_group_id() Optional[str][source]#

Get the current Placement group ID of this worker.

Returns

The current placement group id in hex format of this worker.

property should_capture_child_tasks_in_placement_group#

Get if the current task should capture parent’s placement group.

This returns True if it is called inside a driver.

Returns

Return True if the current task should implicitly

capture the parent placement group.

get_assigned_resources()[source]#

Get the assigned resources to this worker.

By default for tasks, this will return {“CPU”: 1}. By default for actors, this will return {}. This is because actors do not have CPUs assigned to them by default.

Returns

A dictionary mapping the name of a resource to a float, where the float represents the amount of that resource reserved for this worker.

get_runtime_env_string()[source]#

Get the runtime env string used for the current driver or worker.

Returns

The runtime env string currently using by this worker.

property runtime_env#

Get the runtime env used for the current driver or worker.

Returns

The runtime env currently using by this worker. The type of

return value is ray.runtime_env.RuntimeEnv.

property current_actor#

Get the current actor handle of this actor itsself.

Returns

The handle of current actor.

property gcs_address#

Get the GCS address of the ray cluster. :returns: The GCS address of the cluster.