[Serve] Wait for actor name to be cleaned up (#12215)

This commit is contained in:
Simon Mo 2020-12-14 15:09:43 -08:00 committed by GitHub
parent 231518e86f
commit b56db5a22f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,5 @@
import atexit
import time
from functools import wraps
import os
from uuid import UUID
@ -81,9 +82,25 @@ class Client:
Shuts down all processes and deletes all state associated with the
instance.
"""
if not self._shutdown:
if (not self._shutdown) and ray.is_initialized():
ray.get(self._controller.shutdown.remote())
ray.kill(self._controller, no_restart=True)
# Wait for the named actor entry gets removed as well.
started = time.time()
while True:
try:
ray.get_actor(self._controller_name)
if time.time() - started > 5:
logger.warning(
"Waited 5s for Serve to shutdown gracefully but "
"the controller is still not cleaned up. "
"You can ignore this warning if you are shutting "
"down the Ray cluster.")
break
except ValueError: # actor name is removed
break
self._shutdown = True
@_ensure_connected