From 3f0008f98308b42175167e4c1e52b3b699cb7ccd Mon Sep 17 00:00:00 2001 From: BobTheBuidler Date: Tue, 23 Apr 2024 16:42:09 +0000 Subject: [PATCH] feat: log persisted task excs --- a_sync/_task.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/a_sync/_task.py b/a_sync/_task.py index f45e7c12..e702582d 100644 --- a/a_sync/_task.py +++ b/a_sync/_task.py @@ -64,10 +64,23 @@ def __prune_persisted_tasks(): """Remove completed tasks from the set of persisted tasks.""" for task in tuple(__persisted_tasks): if task.done(): - if (e := task.exception()) and not isinstance(e, exceptions.PersistedTaskException): - logger.exception(e) - raise e - __persisted_tasks.discard(task) + e = task.exception() + if e: + if not isinstance(e, exceptions.PersistedTaskException): + logger.exception(e) + raise e + # we have to manually log the traceback that asyncio would usually log + # since we already got the exception from the task and the usual handler will now not run + context = { + 'message': + f'{task.__class__.__name__} exception was never retrieved', + 'exception': e, + 'future': task, + } + if task._source_traceback: + context['source_traceback'] = task._source_traceback + task._loop.call_exception_handler(context) + __persisted_tasks.discard(task) async def __persisted_task_exc_wrap(task: "asyncio.Task[T]") -> T: """