aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/PySide6
diff options
context:
space:
mode:
authorAdrian Herrmann <adrian.herrmann@qt.io>2023-12-15 23:53:42 +0100
committerAdrian Herrmann <adrian.herrmann@qt.io>2023-12-19 20:53:57 +0100
commita78ddd45b5efca163c2fdc78cc6de9c53d3392e5 (patch)
tree7f260eaa9ea882facbadb724219e0e1e5f0edae0 /sources/pyside6/PySide6
parentda9081d40014e63405ec0e88cba5cc58a60ed0ce (diff)
QtAsyncio: Catch keyboard interrupts
Catch keyboard interrupts by catching the SIGINT signal and handling it with the default handler. Register the handler with the QAsyncioEventLoopPolicy so that this is always done when using QtAsyncio. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I7b35367a50ab03eb014faabf6b6a3b21a6a3cd6c Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6/PySide6')
-rw-r--r--sources/pyside6/PySide6/QtAsyncio/events.py3
-rw-r--r--sources/pyside6/PySide6/QtAsyncio/futures.py4
-rw-r--r--sources/pyside6/PySide6/QtAsyncio/tasks.py2
3 files changed, 6 insertions, 3 deletions
diff --git a/sources/pyside6/PySide6/QtAsyncio/events.py b/sources/pyside6/PySide6/QtAsyncio/events.py
index d9bbfc955..c570676cb 100644
--- a/sources/pyside6/PySide6/QtAsyncio/events.py
+++ b/sources/pyside6/PySide6/QtAsyncio/events.py
@@ -12,6 +12,7 @@ import concurrent.futures
import contextvars
import enum
import os
+import signal
import socket
import subprocess
import typing
@@ -64,6 +65,8 @@ class QAsyncioEventLoopPolicy(asyncio.AbstractEventLoopPolicy):
self._application: QCoreApplication = application # type: ignore[assignment]
self._event_loop: typing.Optional[asyncio.AbstractEventLoop] = None
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
+
def get_event_loop(self) -> asyncio.AbstractEventLoop:
if self._event_loop is None:
self._event_loop = QAsyncioEventLoop(self._application)
diff --git a/sources/pyside6/PySide6/QtAsyncio/futures.py b/sources/pyside6/PySide6/QtAsyncio/futures.py
index 7ed8bcb64..f4ac2c561 100644
--- a/sources/pyside6/PySide6/QtAsyncio/futures.py
+++ b/sources/pyside6/PySide6/QtAsyncio/futures.py
@@ -33,7 +33,7 @@ class QAsyncioFuture():
self._state = QAsyncioFuture.FutureState.PENDING
self._result: typing.Any = None
- self._exception: typing.Optional[Exception] = None
+ self._exception: typing.Optional[BaseException] = None
self._callbacks: typing.List[typing.Callable] = list()
@@ -103,7 +103,7 @@ class QAsyncioFuture():
self._schedule_callbacks()
return True
- def exception(self) -> typing.Optional[Exception]:
+ def exception(self) -> typing.Optional[BaseException]:
if self._state == QAsyncioFuture.FutureState.CANCELLED:
raise asyncio.CancelledError
if self.done():
diff --git a/sources/pyside6/PySide6/QtAsyncio/tasks.py b/sources/pyside6/PySide6/QtAsyncio/tasks.py
index 78f9dfb0c..c8e7da7e4 100644
--- a/sources/pyside6/PySide6/QtAsyncio/tasks.py
+++ b/sources/pyside6/PySide6/QtAsyncio/tasks.py
@@ -88,7 +88,7 @@ class QAsyncioTask(futures.QAsyncioFuture):
self._exception = e
except BaseException as e:
self._state = futures.QAsyncioFuture.FutureState.DONE_WITH_EXCEPTION
- self._exception = e # type: ignore[assignment]
+ self._exception = e
else:
if asyncio.futures.isfuture(result):
result.add_done_callback(