From f7469442e35171e77cd04b7d41224fb769e7ed0d Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 11 Jul 2024 19:22:40 -0400 Subject: [PATCH] Use "sclang"-style syntax in `to_asyncio` task logging Just like we've started doing throughout the rest of the actor runtime for reporting (and where "sclang" = "structured conc (s)lang", our little supervision-focused operations syntax i've been playing with in log msg content). Further tweaks: - report the `trio_done_fute` alongside the `main_outcome` value. - add a todo list for supporting `greenback` for pause points. --- tractor/to_asyncio.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/tractor/to_asyncio.py b/tractor/to_asyncio.py index 5564d0e..c37c046 100644 --- a/tractor/to_asyncio.py +++ b/tractor/to_asyncio.py @@ -276,7 +276,10 @@ def _run_asyncio_task( chan._aio_task: asyncio.Task = task # XXX TODO XXX get this actually workin.. XD - # maybe setup `greenback` for `asyncio`-side task REPLing + # -[ ] we need logic to setup `greenback` for `asyncio`-side task + # REPLing.. which should normally be nearly the same as for + # `trio`? + # -[ ] add to a new `.devx._greenback.maybe_init_for_asyncio()`? if ( debug_mode() and @@ -305,15 +308,22 @@ def _run_asyncio_task( msg: str = ( 'Infected `asyncio` task {etype_str}\n' - f'|_{task}\n' ) if isinstance(terr, CancelledError): + msg += ( + f'c)>\n' + f' |_{task}\n' + ) log.cancel( msg.format(etype_str='cancelled') ) else: + msg += ( + f'x)>\n' + f' |_{task}\n' + ) log.exception( - msg.format(etype_str='cancelled') + msg.format(etype_str='errored') ) assert type(terr) is type(aio_err), ( @@ -619,9 +629,10 @@ def run_as_asyncio_guest( # ) def trio_done_callback(main_outcome): - log.info( - f'trio_main finished with\n' - f'|_{main_outcome!r}' + log.runtime( + f'`trio` guest-run finishing with outcome\n' + f'>) {main_outcome}\n' + f'|_{trio_done_fute}\n' ) if isinstance(main_outcome, Error): @@ -643,6 +654,12 @@ def run_as_asyncio_guest( else: trio_done_fute.set_result(main_outcome) + log.info( + f'`trio` guest-run finished with outcome\n' + f')>\n' + f'|_{trio_done_fute}\n' + ) + startup_msg += ( f'-> created {trio_done_callback!r}\n' f'-> scheduling `trio_main`: {trio_main!r}\n' @@ -681,7 +698,8 @@ def run_as_asyncio_guest( # error path in `asyncio`'s runtime..? asyncio.CancelledError, - ) as fute_err: + ) as _fute_err: + fute_err = _fute_err err_message: str = ( 'main `asyncio` task ' )