Long-lived Ray actors

I have a Ray script for a process I’d like to keep running in the background that consumes from a queue of URLs to scrape.

I’d like this script to keep running, even after I run the command. I don’t want to depend on a tmux screen or the like. Is there a way to do this with 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

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
f = ray.get_actor('FooActor')