Fix exit_actor in asyncio mode (#12693)

This commit is contained in:
Simon Mo
2020-12-11 09:35:17 -08:00
committed by GitHub
parent 699ded5328
commit 68d7fa2137
3 changed files with 49 additions and 0 deletions
+14
View File
@@ -351,6 +351,18 @@ cdef execute_task(
# Automatically restrict the GPUs available to this task.
ray.utils.set_cuda_visible_devices(ray.get_gpu_ids())
# Helper method used to exit current asyncio actor.
# This is called when a KeyboardInterrupt is received by the main thread.
# Upon receiving a KeyboardInterrupt signal, Ray will exit the current
# worker. If the worker is processing normal tasks, Ray treat it as task
# cancellation from ray.cancel(object_ref). If the worker is an asyncio
# actor, Ray will exit the actor.
def exit_current_actor_if_asyncio():
if core_worker.current_actor_is_asyncio():
error = SystemExit(0)
error.is_ray_terminate = True
raise error
function_descriptor = CFunctionDescriptorToPython(
ray_function.GetFunctionDescriptor())
@@ -476,6 +488,7 @@ cdef execute_task(
ray.worker.global_worker.debugger_breakpoint = b""
task_exception = False
except KeyboardInterrupt as e:
exit_current_actor_if_asyncio()
raise TaskCancelledError(
core_worker.get_current_task_id())
if c_return_ids.size() == 1:
@@ -483,6 +496,7 @@ cdef execute_task(
# Check for a cancellation that was called when the function
# was exiting and was raised after the except block.
if not check_signals().ok():
exit_current_actor_if_asyncio()
task_exception = True
raise TaskCancelledError(
core_worker.get_current_task_id())