Update named actor API (#8559)

This commit is contained in:
Edward Oakes
2020-05-24 20:08:03 -05:00
committed by GitHub
parent 92c2e41dfd
commit 860eb6f13a
10 changed files with 109 additions and 140 deletions
+21 -7
View File
@@ -1657,7 +1657,22 @@ def wait(object_ids, num_returns=1, timeout=None):
return ready_ids, remaining_ids
def kill(actor):
def get_actor(name):
"""Get a handle to a detached actor.
Gets a handle to a detached actor with the given name. The actor must
have been created with Actor.options(name="name").remote().
Returns:
ActorHandle to the actor.
Raises:
ValueError if the named actor does not exist.
"""
return ray.util.named_actors._get_actor(name)
def kill(actor, no_restart=True):
"""Kill an actor forcefully.
This will interrupt any running tasks on the actor, causing them to fail
@@ -1667,21 +1682,20 @@ def kill(actor):
you can call ``actor.__ray_terminate__.remote()`` instead to queue a
termination task.
In both cases, the worker is actually killed, but it will be restarted by
Ray.
If this actor is reconstructable, an attempt will be made to reconstruct
it.
If the actor is a detached actor, subsequent calls to get its handle via
ray.get_actor will fail.
Args:
actor (ActorHandle): Handle to the actor to kill.
no_restart (bool): Whether or not this actor should be restarted if
it's a restartable actor.
"""
if not isinstance(actor, ray.actor.ActorHandle):
raise ValueError("ray.kill() only supported for actors. "
"Got: {}.".format(type(actor)))
worker = ray.worker.global_worker
worker.check_connected()
worker.core_worker.kill_actor(actor._ray_actor_id, False)
worker.core_worker.kill_actor(actor._ray_actor_id, no_restart)
def cancel(object_id, force=False):