aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/PySide6/QtAsyncio/tasks.py
diff options
context:
space:
mode:
authorLoan Guilbaud <guilbaudl.dev@gmail.com>2025-02-27 22:04:44 +0100
committerLoan Guilbaud <guilbaudl.dev@gmail.com>2025-03-04 11:40:33 +0100
commitc253dcda92cc2efb45197190beaccb926afb120c (patch)
treea11d78340886b5ec0b355f3578ce693964673983 /sources/pyside6/PySide6/QtAsyncio/tasks.py
parent934e4db8ea95843f1585c81b28613c97eca7e2ce (diff)
QtAsyncio: Improve logging when an Exception occurs in a task
When an exception occurs in a task, the logging is not helpful since it prints out nothing specific about the error that occurred. Catching the traceback and printing it out with the task in which it happened brings a lot of details to resolve the exception faster. Task-number: PYSIDE-3001 Pick-to: 6.8 Change-Id: If199da28a37406779ac5bec178fe756d1757b08c Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6/PySide6/QtAsyncio/tasks.py')
-rw-r--r--sources/pyside6/PySide6/QtAsyncio/tasks.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/sources/pyside6/PySide6/QtAsyncio/tasks.py b/sources/pyside6/PySide6/QtAsyncio/tasks.py
index be1809d5c..deabf690d 100644
--- a/sources/pyside6/PySide6/QtAsyncio/tasks.py
+++ b/sources/pyside6/PySide6/QtAsyncio/tasks.py
@@ -4,6 +4,7 @@ from __future__ import annotations
from . import events
from . import futures
+import traceback
from typing import Any
@@ -38,6 +39,8 @@ class QAsyncioTask(futures.QAsyncioFuture):
self._cancelled = False # PYSIDE-2644; see _step
self._cancel_count = 0
self._cancel_message: str | None = None
+ # Store traceback in case of Exception. Useful when exception happens in coroutine
+ self._tb: str = None
# https://docs.python.org/3/library/asyncio-extending.html#task-lifetime-support
asyncio._register_task(self) # type: ignore[arg-type]
@@ -113,6 +116,7 @@ class QAsyncioTask(futures.QAsyncioFuture):
except BaseException as e:
self._state = futures.QAsyncioFuture.FutureState.DONE_WITH_EXCEPTION
self._exception = e
+ self._tb = traceback.format_exc()
else:
if asyncio.futures.isfuture(result):
# If the coroutine yields a future, the task will await its
@@ -159,7 +163,8 @@ class QAsyncioTask(futures.QAsyncioFuture):
"task": self,
"future": (exception_or_future
if asyncio.futures.isfuture(exception_or_future)
- else None)
+ else None),
+ "traceback": self._tb
})
if self.done():