ray.runtime_context.RuntimeContext.get_task_name#

RuntimeContext.get_task_name() str | None[source]#

Get current task name for this worker.

Task name by default is the task’s funciton call string. It can also be specified in options when triggering a task.

Example

import ray

@ray.remote
class Actor:
    def get_task_name(self):
        return ray.get_runtime_context().get_task_name()

@ray.remote
class AsyncActor:
    async def get_task_name(self):
        return ray.get_runtime_context().get_task_name()

@ray.remote
def get_task_name():
    return ray.get_runtime_context().get_task_name()

a = Actor.remote()
b = AsyncActor.remote()
# Task names are available for actor tasks.
print(ray.get(a.get_task_name.remote()))
# Task names are avaiable for async actor tasks.
print(ray.get(b.get_task_name.remote()))
# Task names are available for normal tasks.
# Get default task name
print(ray.get(get_task_name.remote()))
# Get specified task name
print(ray.get(get_task_name.options(name="task_name").remote()))
Actor.get_task_name
AsyncActor.get_task_name
get_task_name
task_nams
Returns:

The current worker’s task name