Handle cancelled-before-proc-created spawn case
It's definitely possible to have a nursery spawn task be cancelled before a `trio.Process` handle is ever returned; we now handle this case as a cancelled-during-spawn scenario. Zombie collection logic also is bypassed in this case.acked_backup
parent
d05885d650
commit
bf6958cdbe
|
@ -230,6 +230,8 @@ async def new_proc(
|
|||
]
|
||||
|
||||
cancelled_during_spawn: bool = False
|
||||
proc: Optional[trio.Process] = None
|
||||
try:
|
||||
try:
|
||||
proc = await trio.open_process(spawn_cmd)
|
||||
|
||||
|
@ -238,9 +240,9 @@ async def new_proc(
|
|||
# wait for actor to spawn and connect back to us
|
||||
# channel should have handshake completed by the
|
||||
# local actor by the time we get a ref to it
|
||||
try:
|
||||
event, chan = await actor_nursery._actor.wait_for_peer(
|
||||
subactor.uid)
|
||||
|
||||
except trio.Cancelled:
|
||||
cancelled_during_spawn = True
|
||||
# we may cancel before the child connects back in which
|
||||
|
@ -320,6 +322,7 @@ async def new_proc(
|
|||
# killing the process too early.
|
||||
log.cancel(f'Hard reap sequence starting for {uid}')
|
||||
|
||||
if proc:
|
||||
with trio.CancelScope(shield=True):
|
||||
|
||||
# don't clobber an ongoing pdb
|
||||
|
@ -337,6 +340,8 @@ async def new_proc(
|
|||
await do_hard_kill(proc)
|
||||
|
||||
log.debug(f"Joined {proc}")
|
||||
else:
|
||||
log.warning(f'Nursery cancelled before sub-proc started')
|
||||
|
||||
if not cancelled_during_spawn:
|
||||
# pop child entry to indicate we no longer managing this
|
||||
|
|
Loading…
Reference in New Issue