Spawn naming and log format tweaks
- rename `.soft_wait()` -> `.soft_kill()` - rename `.do_hard_kill()` -> `.hard_kill()` - adjust any `trio.Process.__repr__()` log msg contents to have the little tree branch prefix: `'|_'`modden_spawn_from_client_req
parent
4f69af872c
commit
50465d4b34
|
@ -196,16 +196,16 @@ async def cancel_on_completion(
|
||||||
result: Any|Exception = await exhaust_portal(portal, actor)
|
result: Any|Exception = await exhaust_portal(portal, actor)
|
||||||
if isinstance(result, Exception):
|
if isinstance(result, Exception):
|
||||||
errors[actor.uid]: Exception = result
|
errors[actor.uid]: Exception = result
|
||||||
log.warning(
|
log.cancel(
|
||||||
'Cancelling subactor due to error:\n'
|
'Cancelling subactor runtime due to error:\n\n'
|
||||||
f'uid: {portal.channel.uid}\n'
|
f'Portal.cancel_actor() => {portal.channel.uid}\n\n'
|
||||||
f'error: {result}\n'
|
f'error: {result}\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.runtime(
|
log.runtime(
|
||||||
'Cancelling subactor gracefully:\n'
|
'Cancelling subactor gracefully:\n\n'
|
||||||
f'uid: {portal.channel.uid}\n'
|
f'Portal.cancel_actor() => {portal.channel.uid}\n\n'
|
||||||
f'result: {result}\n'
|
f'result: {result}\n'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ async def cancel_on_completion(
|
||||||
await portal.cancel_actor()
|
await portal.cancel_actor()
|
||||||
|
|
||||||
|
|
||||||
async def do_hard_kill(
|
async def hard_kill(
|
||||||
proc: trio.Process,
|
proc: trio.Process,
|
||||||
terminate_after: int = 3,
|
terminate_after: int = 3,
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ async def do_hard_kill(
|
||||||
proc.kill()
|
proc.kill()
|
||||||
|
|
||||||
|
|
||||||
async def soft_wait(
|
async def soft_kill(
|
||||||
|
|
||||||
proc: ProcessType,
|
proc: ProcessType,
|
||||||
wait_func: Callable[
|
wait_func: Callable[
|
||||||
|
@ -299,17 +299,20 @@ async def soft_wait(
|
||||||
|
|
||||||
) -> None:
|
) -> None:
|
||||||
'''
|
'''
|
||||||
Wait for proc termination but **dont' yet** teardown
|
Wait for proc termination but **don't yet** teardown
|
||||||
std-streams (since it will clobber any ongoing pdb REPL
|
std-streams since it will clobber any ongoing pdb REPL
|
||||||
session). This is our "soft" (and thus itself cancellable)
|
session.
|
||||||
join/reap on an actor-runtime-in-process.
|
|
||||||
|
This is our "soft"/graceful, and thus itself also cancellable,
|
||||||
|
join/reap on an actor-runtime-in-process shutdown; it is
|
||||||
|
**not** the same as a "hard kill" via an OS signal (for that
|
||||||
|
see `.hard_kill()`).
|
||||||
|
|
||||||
'''
|
'''
|
||||||
uid: tuple[str, str] = portal.channel.uid
|
uid: tuple[str, str] = portal.channel.uid
|
||||||
try:
|
try:
|
||||||
log.cancel(
|
log.cancel(
|
||||||
'Soft waiting on sub-actor proc:\n'
|
'Soft killing sub-actor via `Portal.cancel_actor()`\n'
|
||||||
f'uid: {uid}\n'
|
|
||||||
f'|_{proc}\n'
|
f'|_{proc}\n'
|
||||||
)
|
)
|
||||||
# wait on sub-proc to signal termination
|
# wait on sub-proc to signal termination
|
||||||
|
@ -326,8 +329,9 @@ async def soft_wait(
|
||||||
|
|
||||||
async def cancel_on_proc_deth():
|
async def cancel_on_proc_deth():
|
||||||
'''
|
'''
|
||||||
"Cancel the (actor) cancel" request if we detect
|
"Cancel-the-cancel" request: if we detect that the
|
||||||
that that the underlying sub-process terminated.
|
underlying sub-process exited prior to
|
||||||
|
a `Portal.cancel_actor()` call completing .
|
||||||
|
|
||||||
'''
|
'''
|
||||||
await wait_func(proc)
|
await wait_func(proc)
|
||||||
|
@ -444,14 +448,17 @@ async def trio_proc(
|
||||||
try:
|
try:
|
||||||
# TODO: needs ``trio_typing`` patch?
|
# TODO: needs ``trio_typing`` patch?
|
||||||
proc = await trio.lowlevel.open_process(spawn_cmd)
|
proc = await trio.lowlevel.open_process(spawn_cmd)
|
||||||
|
log.runtime(
|
||||||
log.runtime(f"Started {proc}")
|
'Started new sub-proc\n'
|
||||||
|
f'|_{proc}\n'
|
||||||
|
)
|
||||||
|
|
||||||
# wait for actor to spawn and connect back to us
|
# wait for actor to spawn and connect back to us
|
||||||
# channel should have handshake completed by the
|
# channel should have handshake completed by the
|
||||||
# local actor by the time we get a ref to it
|
# local actor by the time we get a ref to it
|
||||||
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:
|
||||||
cancelled_during_spawn = True
|
cancelled_during_spawn = True
|
||||||
|
@ -512,7 +519,7 @@ async def trio_proc(
|
||||||
# This is a "soft" (cancellable) join/reap which
|
# This is a "soft" (cancellable) join/reap which
|
||||||
# will remote cancel the actor on a ``trio.Cancelled``
|
# will remote cancel the actor on a ``trio.Cancelled``
|
||||||
# condition.
|
# condition.
|
||||||
await soft_wait(
|
await soft_kill(
|
||||||
proc,
|
proc,
|
||||||
trio.Process.wait,
|
trio.Process.wait,
|
||||||
portal
|
portal
|
||||||
|
@ -574,7 +581,7 @@ async def trio_proc(
|
||||||
|
|
||||||
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 hard_kill(proc)
|
||||||
|
|
||||||
log.debug(f"Joined {proc}")
|
log.debug(f"Joined {proc}")
|
||||||
else:
|
else:
|
||||||
|
@ -718,7 +725,7 @@ async def mp_proc(
|
||||||
# This is a "soft" (cancellable) join/reap which
|
# This is a "soft" (cancellable) join/reap which
|
||||||
# will remote cancel the actor on a ``trio.Cancelled``
|
# will remote cancel the actor on a ``trio.Cancelled``
|
||||||
# condition.
|
# condition.
|
||||||
await soft_wait(
|
await soft_kill(
|
||||||
proc,
|
proc,
|
||||||
proc_waiter,
|
proc_waiter,
|
||||||
portal
|
portal
|
||||||
|
|
Loading…
Reference in New Issue