Kill actor child processes on shutdown (#3297)

* example

* add env

* test pg

* change to test

* add atexit test

* Update rllib-env.rst

* comment

* revert unnecessary file

* fix title when actor is idle

* Update python/ray/actor.py

Co-Authored-By: ericl <ekhliang@gmail.com>
This commit is contained in:
Eric Liang
2018-11-13 19:16:42 -08:00
committed by GitHub
parent 577c1dda74
commit 1660c9d627
4 changed files with 95 additions and 6 deletions
+9 -4
View File
@@ -902,6 +902,10 @@ class Worker(object):
self.actor_id = task.actor_creation_id().id()
class_id = arguments[0]
# Set the process group id. This ensures that child processes spawned
# by this actor can be killed with this actor easily on termination.
os.setpgid(os.getpid(), os.getpid())
key = b"ActorClass:" + class_id
# Wait for the actor class key to have been imported by the import
@@ -945,12 +949,14 @@ class Worker(object):
}
if task.actor_id().id() == NIL_ACTOR_ID:
title = "ray_worker:{}()".format(function_name)
next_title = "ray_worker"
else:
actor = self.actors[task.actor_id().id()]
title = "ray_{}:{}()".format(actor.__class__.__name__,
function_name)
next_title = "ray_{}".format(actor.__class__.__name__)
with profiling.profile("task", extra_data=extra_data, worker=self):
with _changeproctitle(title):
with _changeproctitle(title, next_title):
self._process_task(task, execution_info)
# Reset the state fields so the next task can run.
with self.state_lock:
@@ -2163,11 +2169,10 @@ def disconnect(worker=global_worker):
@contextmanager
def _changeproctitle(title):
old_title = setproctitle.getproctitle()
def _changeproctitle(title, next_title):
setproctitle.setproctitle(title)
yield
setproctitle.setproctitle(old_title)
setproctitle.setproctitle(next_title)
def _try_to_compute_deterministic_class_id(cls, depth=5):