mirror of
https://github.com/wassname/ray.git
synced 2026-06-30 17:07:32 +08:00
Clean up actor workers when actor handle goes out of scope. (#617)
This commit is contained in:
committed by
Philipp Moritz
parent
dd7f866a92
commit
d0bfc0a849
@@ -275,6 +275,13 @@ def actor(*args, **kwargs):
|
||||
|
||||
|
||||
def make_actor(Class, num_cpus, num_gpus):
|
||||
# Modify the class to have an additional method that will be used for
|
||||
# terminating the worker.
|
||||
class Class(Class):
|
||||
def __ray_terminate__(self):
|
||||
import os
|
||||
os._exit(0)
|
||||
|
||||
class_id = random_actor_class_id()
|
||||
# The list exported will have length 0 if the class has not been exported
|
||||
# yet, and length one if it has. This is just implementing a bool, but we
|
||||
@@ -389,6 +396,11 @@ def make_actor(Class, num_cpus, num_gpus):
|
||||
def __reduce__(self):
|
||||
raise Exception("Actor objects cannot be pickled.")
|
||||
|
||||
def __del__(self):
|
||||
"""Kill the worker that is running this actor."""
|
||||
actor_method_call(self._ray_actor_id, "__ray_terminate__",
|
||||
self._ray_method_signatures["__ray_terminate__"])
|
||||
|
||||
return NewClass
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user