Add actor.__ray_kill__() to terminate actors immediately (#6523)

This commit is contained in:
Edward Oakes
2019-12-23 23:12:57 -06:00
committed by GitHub
parent 49b0ebf724
commit 6b1a57542e
12 changed files with 173 additions and 5 deletions
+15 -1
View File
@@ -642,7 +642,7 @@ class ActorHandle(object):
self._actor_id.hex())
def __del__(self):
"""Kill the worker that is running this actor."""
"""Terminate the worker that is running this actor."""
# TODO(swang): Also clean up forked actor handles.
# Kill the worker if this is the original actor handle, created
# with Class.remote(). TODO(rkn): Even without passing handles around,
@@ -671,6 +671,20 @@ class ActorHandle(object):
finally:
self.__ray_terminate__._actor_hard_ref = None
def __ray_kill__(self):
"""Kill the actor that this actor handle refers to immediately.
This will cause any outstanding tasks submitted to the actor to fail
and the actor to exit in the same way as if it crashed. In general,
you should prefer to just delete the actor handle and let it clean up
gracefull.
Returns:
None.
"""
worker = ray.worker.get_global_worker()
worker.core_worker.kill_actor(self._ray_actor_id)
@property
def _actor_id(self):
return self._ray_actor_id