diff options
author | Adrian Herrmann <[email protected]> | 2023-12-16 01:40:34 +0100 |
---|---|---|
committer | Adrian Herrmann <[email protected]> | 2023-12-20 00:22:49 +0100 |
commit | 3bbe8e509938dc7fe0a24811a56f038c2c2b9423 (patch) | |
tree | b578b6347bacf6d2b1358ffa65a9aee55a01648a /examples/async | |
parent | a78ddd45b5efca163c2fdc78cc6de9c53d3392e5 (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 <[email protected]>
Reviewed-by: Cristian Maureira-Fredes <[email protected]>
Diffstat (limited to 'examples/async')
-rw-r--r-- | examples/async/eratosthenes/eratosthenes_asyncio.py | 6 | ||||
-rw-r--r-- | examples/async/minimal/minimal_asyncio.py | 5 |
2 files changed, 4 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() |