Drop asyncio-cancelled-itself msg for now, report task names

310_plus
Tyler Goodlet 2022-06-26 13:49:00 -04:00
parent 9e37bb22e1
commit 0b1c1ac568
1 changed files with 16 additions and 11 deletions

View File

@ -259,6 +259,7 @@ def _run_asyncio_task(
nonlocal chan nonlocal chan
aio_err = chan._aio_err aio_err = chan._aio_err
task_err: Optional[BaseException] = None task_err: Optional[BaseException] = None
tname = task.get_name()
# only to avoid ``asyncio`` complaining about uncaptured # only to avoid ``asyncio`` complaining about uncaptured
# task exceptions # task exceptions
@ -268,9 +269,10 @@ def _run_asyncio_task(
task_err = terr task_err = terr
if isinstance(terr, CancelledError): if isinstance(terr, CancelledError):
log.cancel(f'`asyncio` task cancelled: {task.get_name()}') log.cancel(
f'infected `asyncio` task cancelled: {tname}')
else: 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?' assert type(terr) is type(aio_err), 'Asyncio task error mismatch?'
@ -285,21 +287,24 @@ def _run_asyncio_task(
# We might want to change this in the future though. # We might want to change this in the future though.
from_aio.close() from_aio.close()
if type(aio_err) is CancelledError: # if type(aio_err) is CancelledError:
log.cancel("infected task was cancelled") # if not task_err:
# log.cancel(
# f"infected task {tname} cancelled itself, was not ``trio``"
# )
# TODO: show that the cancellation originated # TODO: show that the cancellation originated
# from the ``trio`` side? right? # from the ``trio`` side? right?
# if cancel_scope.cancelled: # if cancel_scope.cancelled:
# raise aio_err from err # raise aio_err from err
elif task_err is None: if task_err is None:
assert aio_err assert aio_err
aio_err.with_traceback(aio_err.__traceback__) aio_err.with_traceback(aio_err.__traceback__)
msg = ''.join(traceback.format_exception(type(aio_err))) # msg = ''.join(traceback.format_exception(type(aio_err)))
log.error( # log.error(
f'infected task errorred:\n{msg}' # f'infected task errorred:\n{msg}'
) # )
# raise any ``asyncio`` side error. # raise any ``asyncio`` side error.
raise aio_err raise aio_err
@ -392,8 +397,8 @@ async def run_task(
) -> Any: ) -> Any:
''' '''
Run an ``asyncio`` async function or generator in a task, return Run an ``asyncio`` async function or generator in a new task, block
or stream the result back to ``trio``. and return the result back to ``trio``.
''' '''
# simple async func # simple async func