Grab lock if cancelled during spawn before hard kill

immediate_remote_cancels
Tyler Goodlet 2021-10-15 17:53:12 -04:00
parent 5cfac58873
commit b3c4851ffb
1 changed files with 8 additions and 7 deletions

View File

@ -229,7 +229,7 @@ async def new_proc(
subactor.loglevel subactor.loglevel
] ]
cancel_during_spawn: bool = False cancelled_during_spawn: bool = False
try: try:
proc = await trio.open_process(spawn_cmd) proc = await trio.open_process(spawn_cmd)
@ -242,8 +242,7 @@ async def new_proc(
event, chan = await actor_nursery._actor.wait_for_peer( event, chan = await actor_nursery._actor.wait_for_peer(
subactor.uid) subactor.uid)
except trio.Cancelled: except trio.Cancelled:
cancel_during_spawn = True cancelled_during_spawn = True
# we may cancel before the child connects back in which # we may cancel before the child connects back in which
# case avoid clobbering the pdb tty. # case avoid clobbering the pdb tty.
if debug_mode(): if debug_mode():
@ -312,15 +311,17 @@ async def new_proc(
log.cancel(f'Hard reap sequence starting for {uid}') log.cancel(f'Hard reap sequence starting for {uid}')
with trio.CancelScope(shield=True): with trio.CancelScope(shield=True):
# don't clobber an ongoing pdb
await maybe_wait_for_debugger()
# don't clobber an ongoing pdb
if cancelled_during_spawn:
# Try again to avoid TTY clobbering. # Try again to avoid TTY clobbering.
if cancel_during_spawn and debug_mode():
async with acquire_debug_lock(uid): async with acquire_debug_lock(uid):
with trio.move_on_after(0.5): with trio.move_on_after(0.5):
await proc.wait() await proc.wait()
if is_root_process():
await maybe_wait_for_debugger()
if proc.poll() is None: if proc.poll() is None:
log.cancel(f"Attempting to hard kill {proc}") log.cancel(f"Attempting to hard kill {proc}")
await do_hard_kill(proc) await do_hard_kill(proc)