Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drop asyncio-cancelled-itself msg for now, report task names
Browse files Browse the repository at this point in the history
goodboy committed Jun 26, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 9e37bb2 commit 0b1c1ac
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions tractor/to_asyncio.py
Original file line number Diff line number Diff line change
@@ -259,6 +259,7 @@ def cancel_trio(task: asyncio.Task) -> None:
nonlocal chan
aio_err = chan._aio_err
task_err: Optional[BaseException] = None
tname = task.get_name()

# only to avoid ``asyncio`` complaining about uncaptured
# task exceptions
@@ -268,9 +269,10 @@ def cancel_trio(task: asyncio.Task) -> None:
task_err = terr

if isinstance(terr, CancelledError):
log.cancel(f'`asyncio` task cancelled: {task.get_name()}')
log.cancel(
f'infected `asyncio` task cancelled: {tname}')
else:
log.exception(f'`asyncio` task: {task.get_name()} errored')
log.exception(f'`asyncio` task: {tname} errored')

assert type(terr) is type(aio_err), 'Asyncio task error mismatch?'

@@ -285,21 +287,24 @@ def cancel_trio(task: asyncio.Task) -> None:
# We might want to change this in the future though.
from_aio.close()

if type(aio_err) is CancelledError:
log.cancel("infected task was cancelled")
# if type(aio_err) is CancelledError:
# if not task_err:
# log.cancel(
# f"infected task {tname} cancelled itself, was not ``trio``"
# )

# TODO: show that the cancellation originated
# from the ``trio`` side? right?
# if cancel_scope.cancelled:
# raise aio_err from err

elif task_err is None:
if task_err is None:
assert aio_err
aio_err.with_traceback(aio_err.__traceback__)
msg = ''.join(traceback.format_exception(type(aio_err)))
log.error(
f'infected task errorred:\n{msg}'
)
# msg = ''.join(traceback.format_exception(type(aio_err)))
# log.error(
# f'infected task errorred:\n{msg}'
# )

# raise any ``asyncio`` side error.
raise aio_err
@@ -392,8 +397,8 @@ async def run_task(

) -> Any:
'''
Run an ``asyncio`` async function or generator in a task, return
or stream the result back to ``trio``.
Run an ``asyncio`` async function or generator in a new task, block
and return the result back to ``trio``.
'''
# simple async func

0 comments on commit 0b1c1ac

Please sign in to comment.