From 2ec3ff46cda2eb940d498b6491381b7d1d4add45 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 29 Jul 2025 15:01:47 -0400 Subject: [PATCH] Log "out-of-layer" cancellation in `._rpc._invoke()` Similar to what was just changed for `Context.repr_state`, when the child task is cancelled but by a different "layer" of the runtime (i.e. a `Portal.cancel_actor()` / `SIGINT`-to-process canceller) we don't dump a traceback instead just `log.cancel()` emit. --- tractor/_rpc.py | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/tractor/_rpc.py b/tractor/_rpc.py index 023bae17..5c53f267 100644 --- a/tractor/_rpc.py +++ b/tractor/_rpc.py @@ -661,7 +661,7 @@ async def _invoke( tn: Nursery rpc_ctx_cs: CancelScope async with ( - collapse_eg(), + collapse_eg(hide_tb=False), trio.open_nursery() as tn, msgops.maybe_limit_plds( ctx=ctx, @@ -854,24 +854,44 @@ async def _invoke( f'after having {ctx.repr_state!r}\n' ) if merr: - logmeth: Callable = log.error - if isinstance(merr, ContextCancelled): - logmeth: Callable = log.runtime + if ( + # ctxc: by `Context.cancel()` + isinstance(merr, ContextCancelled) - if not isinstance(merr, RemoteActorError): - tb_str: str = ''.join(traceback.format_exception(merr)) + # out-of-layer cancellation, one of: + # - actorc: by `Portal.cancel_actor()` + # - OSc: by SIGINT or `Process.signal()` + or ( + isinstance(merr, trio.Cancelled) + and + ctx.canceller + ) + ): + logmeth: Callable = log.cancel + descr_str += ( + f' with {merr!r}\n' + ) + + elif ( + not isinstance(merr, RemoteActorError) + ): + tb_str: str = ''.join( + traceback.format_exception(merr) + ) descr_str += ( f'\n{merr!r}\n' # needed? f'{tb_str}\n' - f'\n' - f'scope_error:\n' - f'{scope_err!r}\n' ) else: - descr_str += f'\n{merr!r}\n' + descr_str += ( + f'{merr!r}\n' + ) else: - descr_str += f'\nwith final result {ctx.outcome!r}\n' + descr_str += ( + f'\n' + f'with final result {ctx.outcome!r}\n' + ) logmeth( f'{message}\n'