aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/PySide6/QtAsyncio
diff options
context:
space:
mode:
authorAdrian Herrmann <adrian.herrmann@qt.io>2023-12-16 01:40:34 +0100
committerAdrian Herrmann <adrian.herrmann@qt.io>2023-12-20 00:22:49 +0100
commit3bbe8e509938dc7fe0a24811a56f038c2c2b9423 (patch)
treeb578b6347bacf6d2b1358ffa65a9aee55a01648a /sources/pyside6/PySide6/QtAsyncio
parenta78ddd45b5efca163c2fdc78cc6de9c53d3392e5 (diff)
QtAsyncio: Add QtAsyncio.run() function
Add a QtAsyncio.run() function as the new recommended method to launch QtAsyncio programs. This abstracts the event loop policy and reduces the API to one single call. Additionally, this will allow to transparently replace the event loop policy with a loop factory when event loop policies are removed in Python 3.15 following their deprecation in 3.12. More information: https://discuss.python.org/t/removing-the-asyncio-policy-system-asyncio-set-event-loop-policy-in-python-3-15/37553 Pick-to: 6.6 Task-number: PYSIDE-769 Change-Id: I59d7eeb81debe92315351995f041caead4f51d8b Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/pyside6/PySide6/QtAsyncio')
-rw-r--r--sources/pyside6/PySide6/QtAsyncio/__init__.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/sources/pyside6/PySide6/QtAsyncio/__init__.py b/sources/pyside6/PySide6/QtAsyncio/__init__.py
index 2c673e405..68de6ec39 100644
--- a/sources/pyside6/PySide6/QtAsyncio/__init__.py
+++ b/sources/pyside6/PySide6/QtAsyncio/__init__.py
@@ -7,8 +7,20 @@ from .events import (
from .futures import QAsyncioFuture
from .tasks import QAsyncioTask
+import asyncio
+import typing
+
__all__ = [
"QAsyncioEventLoopPolicy", "QAsyncioEventLoop",
"QAsyncioHandle", "QAsyncioTimerHandle",
"QAsyncioFuture", "QAsyncioTask"
]
+
+
+def run(coro: typing.Optional[typing.Coroutine] = None, *,
+ debug: typing.Optional[bool] = None) -> None:
+ """Run the event loop."""
+ asyncio.set_event_loop_policy(QAsyncioEventLoopPolicy())
+ if coro:
+ asyncio.ensure_future(coro)
+ asyncio.run(asyncio.Event().wait(), debug=debug)