Skip to content

Commit

Permalink
Graceful cancel actors before hard reaping
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Nov 29, 2021
1 parent eb9f80b commit ae4e7c7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tractor/_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ae4e7c7

Please sign in to comment.