aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/PySide6/QtAsyncio/events.py
diff options
context:
space:
mode:
authorAdrian Herrmann <adrian.herrmann@qt.io>2023-10-10 19:05:06 +0200
committerAdrian Herrmann <adrian.herrmann@qt.io>2023-10-11 13:37:47 +0200
commit2199b95e00fbf0b06d23659274e080a7d75b5988 (patch)
tree833ecf4f0c358d17862d75b1891ec066f37a75a2 /sources/pyside6/PySide6/QtAsyncio/events.py
parenta7f7ab6ef12005f4ca86c5a4934c33d2539a23e5 (diff)
QtAsyncio: Don't schedule events when quitting app
Do not schedule events from asyncio when the app is quit from outside the event loop, as this would cause events to be enqueued after the event loop was destroyed. Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: Ib9ff3949653783e4a9484a8a28f1c0010dcff33f Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/PySide6/QtAsyncio/events.py')
-rw-r--r--sources/pyside6/PySide6/QtAsyncio/events.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/sources/pyside6/PySide6/QtAsyncio/events.py b/sources/pyside6/PySide6/QtAsyncio/events.py
index 4e53ed499..d64d7d22b 100644
--- a/sources/pyside6/PySide6/QtAsyncio/events.py
+++ b/sources/pyside6/PySide6/QtAsyncio/events.py
@@ -77,6 +77,10 @@ class QAsyncioEventLoop(asyncio.BaseEventLoop):
self._thread = QThread.currentThread()
self._closed = False
+
+ self._quit_from_inside = False
+ self._quit_from_outside = False
+
self._asyncgens: typing.Set[collections.abc.AsyncGenerator] = set()
# Starting with Python 3.11, this must be an instance of
@@ -89,6 +93,8 @@ class QAsyncioEventLoop(asyncio.BaseEventLoop):
self._debug = bool(os.getenv("PYTHONASYNCIODEBUG", False))
+ self._application.aboutToQuit.connect(self._about_to_quit_cb)
+
# Running and stopping the loop
def _run_until_complete_cb(self, future: futures.QAsyncioFuture) -> None:
@@ -130,12 +136,17 @@ class QAsyncioEventLoop(asyncio.BaseEventLoop):
self._application.exec()
asyncio.events._set_running_loop(None)
+ def _about_to_quit_cb(self):
+ if not self._quit_from_inside:
+ self._quit_from_outside = True
+
def stop(self) -> None:
if self._future_to_complete is not None:
if self._future_to_complete.done():
self._future_to_complete = None
else:
return
+ self._quit_from_inside = True
self._application.quit()
def is_running(self) -> bool:
@@ -468,7 +479,7 @@ class QAsyncioHandle():
self._start()
def _schedule_event(self, timeout: int, func: typing.Callable) -> None:
- if not self._loop.is_closed():
+ if not self._loop.is_closed() and not self._loop._quit_from_outside:
QTimer.singleShot(timeout, func)
def _start(self) -> None: