Skip to content

Instantly share code, notes, and snippets.

@stephanie-wang
Last active July 14, 2020 23:50
Show Gist options
  • Save stephanie-wang/c635a3df967df75ed4acc0cc5e75aed5 to your computer and use it in GitHub Desktop.
Save stephanie-wang/c635a3df967df75ed4acc0cc5e75aed5 to your computer and use it in GitHub Desktop.
Detached job
import ray
from ray.test_utils import SignalActor
@ray.remote
class Driver:
def __init__(self):
pass
def start(self, signal):
signal.send.remote()
# Driver code here. Any spawned tasks/actors will be owned by this actor
# so they will not get cleaned up until this actor is dead.
# ...
ray.init()
driver = Driver.options(name="my_job").remote() # Detached actor.
s = SignalActor.remote()
driver.start.remote(s)
ray.get(s.wait.remote()) # Wait for the `Driver.start` task to begin before exiting.
@ericl
Copy link

ericl commented Jul 14, 2020

We could make this a utility too, e.g.,

def main():
   ...

# detaches the main function as a named actor
ray.util.run_as_detached_job(main, name="job_name")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment