From 7eb465a69941535e0c9407fbd84187f0c828ac61 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 25 Nov 2021 17:14:16 -0500 Subject: [PATCH] Graceful cancel actors before hard reaping --- tractor/_spawn.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tractor/_spawn.py b/tractor/_spawn.py index bca812d..4fb05d7 100644 --- a/tractor/_spawn.py +++ b/tractor/_spawn.py @@ -295,7 +295,17 @@ async def new_proc( # ``trio.Process.__aexit__()`` (it tears down stdio # which will kill any waiting remote pdb trace). # This is a "soft" (cancellable) join/reap. - await proc.wait() + try: + await proc.wait() + except trio.Cancelled: + # if cancelled during a soft wait cancel the child + # actor before entering the hard reap + # sequence below. This means we try to do a + # graceful teardown before getting out zombie + # killing tools. + with trio.CancelScope(shield=True): + await portal.cancel_actor() + raise # cancel result waiter that may have been spawned in # tandem if not done already