Fix worker exit cleanup (#6450)

* working but ugly

* comments

* proper but hanging in grpc server destructor

* grpc server shutdown deadline

* fix disconnect

* lint

* shutdown_only in test

* replace shutdown
This commit is contained in:
Edward Oakes
2019-12-13 16:52:50 -08:00
committed by GitHub
parent 3cb499632e
commit e2b7459bfc
8 changed files with 40 additions and 47 deletions
+8 -7
View File
@@ -431,6 +431,7 @@ class Worker(object):
signal.signal(signal.SIGTERM, sigterm_handler)
self.core_worker.run_task_loop()
sys.exit(0)
def get_gpu_ids():
@@ -834,6 +835,12 @@ def shutdown(exiting_interpreter=False):
disconnect(exiting_interpreter)
# We need to destruct the core worker here because after this function,
# we will tear down any processes spawned by ray.init() and the background
# IO thread in the core worker doesn't currently handle that gracefully.
if hasattr(global_worker, "core_worker"):
del global_worker.core_worker
# Disconnect global state from GCS.
ray.state.state.disconnect()
@@ -843,7 +850,7 @@ def shutdown(exiting_interpreter=False):
_global_node.kill_all_processes(check_alive=False, allow_graceful=True)
_global_node = None
# TODO(rkn): Instead of manually reseting some of the worker fields, we
# TODO(rkn): Instead of manually resetting some of the worker fields, we
# should simply set "global_worker" to equal "None" or something like that.
global_worker.set_mode(None)
global_worker._post_get_hooks = []
@@ -1332,12 +1339,6 @@ def disconnect(exiting_interpreter=False):
worker.cached_functions_to_run = []
worker.serialization_context_map.clear()
# We need to destruct the core worker here because after this function,
# we will tear down any processes spawned by ray.init() and the background
# threads in the core worker don't currently handle that gracefully.
if hasattr(worker, "core_worker"):
del worker.core_worker
@contextmanager
def _changeproctitle(title, next_title):