Terminating Actors
Contents
Terminating Actors#
Automatic termination#
Actor processes will be terminated automatically when all copies of the actor handle have gone out of scope in Python, or if the original creator process dies.
Terminating an actor automatically when the initial actor handle goes out of scope hasn’t been implemented in Java yet.
Terminating an actor automatically when the initial actor handle goes out of scope hasn’t been implemented in C++ yet.
Manual termination within the actor#
If necessary, you can manually terminate an actor from within one of the actor methods. This will kill the actor process and release resources associated/assigned to the actor.
ray.actor.exit_actor()
This approach should generally not be necessary as actors are automatically garbage
collected. The ObjectRef
resulting from the task can be waited on to wait
for the actor to exit (calling ray.get()
on it will raise a RayActorError
).
Ray.exitActor();
Garbage collection for actors haven’t been implemented yet, so this is currently the
only way to terminate an actor gracefully. The ObjectRef
resulting from the task
can be waited on to wait for the actor to exit (calling ObjectRef::get
on it will
throw a RayActorException
).
ray::ExitActor();
Garbage collection for actors haven’t been implemented yet, so this is currently the
only way to terminate an actor gracefully. The ObjectRef
resulting from the task
can be waited on to wait for the actor to exit (calling ObjectRef::Get
on it will
throw a RayActorException
).
Note that this method of termination will wait until any previously submitted tasks finish executing and then exit the process gracefully with sys.exit.
Manual termination via an actor handle#
You can terminate an actor forcefully.
ray.kill(actor_handle)
actorHandle.kill();
actor_handle.Kill();
This will call the exit syscall from within the actor, causing it to exit immediately and any pending tasks to fail.
This will not go through the normal
Python sys.exit teardown logic, so any exit handlers installed in the actor using
atexit
will not be called.
This will not go through the normal Java System.exit teardown logic, so any
shutdown hooks installed in the actor using Runtime.addShutdownHook(...)
will
not be called.
This will not go through the normal
C++ std::exit teardown logic, so any exit handlers installed in the actor using
std::atexit
will not be called.