From 870466471983720b4db8fd94e420a83b0f44ee01 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 17 Nov 2021 18:56:23 -0500 Subject: [PATCH] Reverse the order for asyncio cancelleds? I dunno why --- tractor/to_asyncio.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tractor/to_asyncio.py b/tractor/to_asyncio.py index 5607031..7409d7c 100644 --- a/tractor/to_asyncio.py +++ b/tractor/to_asyncio.py @@ -72,6 +72,7 @@ def _run_asyncio_task( aio_err: Optional[BaseException] = None async def wait_on_coro_final_result( + to_trio: trio.MemorySendChannel, coro: Awaitable, aio_task_complete: trio.Event, @@ -89,6 +90,7 @@ def _run_asyncio_task( aio_err = err from_aio._err = aio_err raise + finally: aio_task_complete.set() if result != orig and aio_err is None: @@ -112,15 +114,17 @@ def _run_asyncio_task( try: aio_err = task.exception() except CancelledError as cerr: - log.exception("infected task was cancelled") - # raise - aio_err = cerr - - if aio_err: - log.exception(f"infected task errorred with {type(aio_err)}") - from_aio._err = aio_err + log.cancel("infected task was cancelled") + from_aio._err = cerr from_aio.close() cancel_scope.cancel() + else: + if aio_err is not None: + log.exception(f"infected task errorred:") + from_aio._err = aio_err + # order is opposite here + cancel_scope.cancel() + from_aio.close() task.add_done_callback(cancel_trio)