aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sources/pyside6/PySide6/QtAsyncio/events.py4
-rw-r--r--sources/pyside6/PySide6/QtAsyncio/tasks.py7
2 files changed, 9 insertions, 2 deletions
diff --git a/sources/pyside6/PySide6/QtAsyncio/events.py b/sources/pyside6/PySide6/QtAsyncio/events.py
index 36c7fea97..f99b601f7 100644
--- a/sources/pyside6/PySide6/QtAsyncio/events.py
+++ b/sources/pyside6/PySide6/QtAsyncio/events.py
@@ -598,7 +598,9 @@ class QAsyncioEventLoop(asyncio.BaseEventLoop, QObject):
def default_exception_handler(self, context: dict[str, Any]) -> None:
# TODO
if context["message"]:
- print(context["message"])
+ print(f"{context["message"]} from task {context["task"]._name},"+
+ "read the following traceback:")
+ print(context["traceback"])
def call_exception_handler(self, context: dict[str, Any]) -> None:
if self._exception_handler is not None:
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():