Long-lived Ray actors

Great question! You can absolutely do this with Ray. Please check out Ray’s documentation on actor lifetimes. https://docs.ray.io/en/master/actors.html#actor-lifetimes

For example, here’s a script that creates an actor that outlives the script.

# First start Ray cluster
ray start --head

Create actor that outlives this script

import ray
ray.init(address='auto')

@ray.remote
class Foo:
    def method(self):
        return 1

f = Foo.options(name='FooActor', lifetime='detached').remote()

# Script exits

Then, you can retrieve that actor from another script using

import ray
ray.init(address='auto')
f = ray.get_actor('FooActor')
ray.get(f.method.remote())
3 Likes