Try to improve async stack traces for exceptions in tasks (#1442)

* Try to improve async stack traces for exceptions in tasks

* Lint
This commit is contained in:
Nuno Campos
2024-08-22 21:23:48 +00:00
committed by GitHub
parent 0720b931e8
commit 7074604204
+12 -11
View File
@@ -120,14 +120,14 @@ class AsyncBackgroundExecutor(AsyncContextManager):
def done(self, task: asyncio.Task) -> None:
try:
task.result()
except GraphInterrupt:
# This exception is an interruption signal, not an error
# so we don't want to re-raise it on exit
self.tasks.pop(task)
except BaseException:
pass
else:
if exc := task.exception():
# This exception is an interruption signal, not an error
# so we don't want to re-raise it on exit
if isinstance(exc, GraphInterrupt):
self.tasks.pop(task)
else:
self.tasks.pop(task)
except asyncio.CancelledError:
self.tasks.pop(task)
async def __aenter__(self) -> Submit:
@@ -146,12 +146,13 @@ class AsyncBackgroundExecutor(AsyncContextManager):
# wait for all tasks to finish
if self.tasks:
await asyncio.wait(self.tasks)
# re-raise the first exception that occurred in a task
# if there's already an exception being raised, don't raise another one
if exc_type is None:
# if there's already an exception being raised, don't raise another one
# re-raise the first exception that occurred in a task
for task in self.tasks:
try:
task.result()
if exc := task.exception():
raise exc
except asyncio.CancelledError:
pass