aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/PySide6/QtAsyncio/events.py
diff options
context:
space:
mode:
authorAdrian Herrmann <adrian.herrmann@qt.io>2023-09-12 01:19:33 +0200
committerAdrian Herrmann <adrian.herrmann@qt.io>2023-09-12 11:55:32 +0200
commita53379153abe1fc3b1ac5625714c6002510c6d73 (patch)
treebea6c72fb2ca4d6cea770ddc5fcf88a051c7a785 /sources/pyside6/PySide6/QtAsyncio/events.py
parent971c5944415cd557112ff046c4b0c41e8b0d5b05 (diff)
QtAsyncio: Add queues test
Add a test for the asyncio queue for consumer/producer scenarios. Additionally, fix a few bugs exposed by this test through the increased code coverage. Task-number: PYSIDE-769 Change-Id: I18e3be6d059b758868a7598b58704db216bcdcc8 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6/PySide6/QtAsyncio/events.py')
-rw-r--r--sources/pyside6/PySide6/QtAsyncio/events.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/sources/pyside6/PySide6/QtAsyncio/events.py b/sources/pyside6/PySide6/QtAsyncio/events.py
index 94930082d..4e53ed499 100644
--- a/sources/pyside6/PySide6/QtAsyncio/events.py
+++ b/sources/pyside6/PySide6/QtAsyncio/events.py
@@ -467,8 +467,12 @@ class QAsyncioHandle():
self._state = QAsyncioHandle.HandleState.PENDING
self._start()
+ def _schedule_event(self, timeout: int, func: typing.Callable) -> None:
+ if not self._loop.is_closed():
+ QTimer.singleShot(timeout, func)
+
def _start(self) -> None:
- QTimer.singleShot(self._timeout, lambda: self._cb())
+ self._schedule_event(self._timeout, lambda: self._cb())
@Slot()
def _cb(self) -> None:
@@ -487,7 +491,7 @@ class QAsyncioHandle():
if self._state == QAsyncioHandle.HandleState.PENDING:
self._state = QAsyncioHandle.HandleState.CANCELLED
# The old timer that was created in _start will still trigger but _cb won't do anything.
- QTimer.singleShot(0, lambda: self._cancel_exception())
+ self._schedule_event(0, lambda: self._cancel_exception())
def cancelled(self) -> bool:
return self._state == QAsyncioHandle.HandleState.CANCELLED