diff --git a/python/ray/worker.py b/python/ray/worker.py index 13095a622..c87954d8a 100644 --- a/python/ray/worker.py +++ b/python/ray/worker.py @@ -1669,12 +1669,11 @@ def disconnect(exiting_interpreter=False): worker.function_actor_manager.reset_cache() worker.serialization_context_map.clear() - if not exiting_interpreter: - if hasattr(worker, "raylet_client"): - del worker.raylet_client - - if hasattr(worker, "core_worker"): - del worker.core_worker + # 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