Skip to content

Commit

Permalink
Grab lock if cancelled during spawn before hard kill
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Oct 15, 2021
1 parent 5cfac58 commit 34ed193
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions tractor/_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ async def new_proc(
subactor.loglevel
]

cancel_during_spawn: bool = False
cancelled_during_spawn: bool = False
try:
proc = await trio.open_process(spawn_cmd)

Expand All @@ -242,8 +242,7 @@ async def new_proc(
event, chan = await actor_nursery._actor.wait_for_peer(
subactor.uid)
except trio.Cancelled:
cancel_during_spawn = True

cancelled_during_spawn = True
# we may cancel before the child connects back in which
# case avoid clobbering the pdb tty.
if debug_mode():
Expand Down Expand Up @@ -312,15 +311,17 @@ async def new_proc(
log.cancel(f'Hard reap sequence starting for {uid}')

with trio.CancelScope(shield=True):
# don't clobber an ongoing pdb
await maybe_wait_for_debugger()

# Try again to avoid TTY clobbering.
if cancel_during_spawn and debug_mode():
# don't clobber an ongoing pdb
if cancelled_during_spawn:
# Try again to avoid TTY clobbering.
async with acquire_debug_lock(uid):
with trio.move_on_after(0.5):
await proc.wait()

if is root_process():
await maybe_wait_for_debugger()

if proc.poll() is None:
log.cancel(f"Attempting to hard kill {proc}")
await do_hard_kill(proc)
Expand Down

0 comments on commit 34ed193

Please sign in to comment.