Run some callback on every worker and any new worker in the future

How severe does this issue affect your experience of using Ray? Low

I have a use case where I need to ensure that some code ( i.e. init() ) runs at the launch of every worker process and any new subsequent worker process in the future.

For now I am just inserting the code into every Ray task and actor like so:

@ray.remote
def task_a():
    init()

@ray.remote
def task_b():
    init()

@ray.remote
class Actor_a():
    def __init__(self):
        init()

However defining this init() gets redundant if I have very many Ray tasks or actors.

ray.worker.global_worker.run_function_on_all_workers seemed promising but looks like it is on the deprecation path now. Any other ideas or tips?

run_function_on_all_workers was the best solution before, as you said, it is deprecated, and not a public API. I think we should build new APIs to achieve this. Do you mind creating an enhancement request to Ray repo? Issues · ray-project/ray · GitHub

1 Like