aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/async/eratosthenes/eratosthenes_asyncio.py6
-rw-r--r--examples/async/minimal/minimal_asyncio.py5
-rw-r--r--sources/pyside6/PySide6/QtAsyncio/__init__.py12
3 files changed, 16 insertions, 7 deletions
diff --git a/examples/async/eratosthenes/eratosthenes_asyncio.py b/examples/async/eratosthenes/eratosthenes_asyncio.py
index f24a06145..598d9b4bd 100644
--- a/examples/async/eratosthenes/eratosthenes_asyncio.py
+++ b/examples/async/eratosthenes/eratosthenes_asyncio.py
@@ -5,7 +5,7 @@ from PySide6.QtCore import (Qt, QObject, Signal, Slot)
from PySide6.QtGui import (QColor, QFont, QPalette)
from PySide6.QtWidgets import (QApplication, QGridLayout, QLabel, QMainWindow, QVBoxLayout, QWidget)
-from PySide6.QtAsyncio import QAsyncioEventLoopPolicy
+import PySide6.QtAsyncio as QtAsyncio
import asyncio
import sys
@@ -131,6 +131,4 @@ if __name__ == "__main__":
main_window.show()
- asyncio.set_event_loop_policy(QAsyncioEventLoopPolicy())
- asyncio.ensure_future(eratosthenes.start())
- asyncio.get_event_loop().run_forever()
+ QtAsyncio.run(eratosthenes.start())
diff --git a/examples/async/minimal/minimal_asyncio.py b/examples/async/minimal/minimal_asyncio.py
index 4e6f712c3..4545f35d5 100644
--- a/examples/async/minimal/minimal_asyncio.py
+++ b/examples/async/minimal/minimal_asyncio.py
@@ -4,7 +4,7 @@
from PySide6.QtCore import (Qt, QObject, Signal, Slot)
from PySide6.QtWidgets import (QApplication, QLabel, QMainWindow, QPushButton, QVBoxLayout, QWidget)
-from PySide6.QtAsyncio import QAsyncioEventLoopPolicy
+import PySide6.QtAsyncio as QtAsyncio
import asyncio
import sys
@@ -59,5 +59,4 @@ if __name__ == "__main__":
main_window.show()
- asyncio.set_event_loop_policy(QAsyncioEventLoopPolicy())
- asyncio.get_event_loop().run_forever()
+ QtAsyncio.run()
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)