Skip to content

Commit 930c53a

Browse files
committed
Support Python 3.14.
1 parent 73e6cbe commit 930c53a

2 files changed

Lines changed: 26 additions & 23 deletions

File tree

.github/workflows/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
matrix:
2222
os: [ubuntu, windows, macos-x86_64, macos-arm64]
23-
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
23+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14-dev"]
2424
qt-version: ["pyside2", "pyside6", "pyqt5", "pyqt6"]
2525
include:
2626
- os: ubuntu
@@ -42,6 +42,8 @@ jobs:
4242
qt-version: pyside2
4343
- python-version: "3.13"
4444
qt-version: pyside2
45+
- python-version: "3.14-dev"
46+
qt-version: pyside2
4547
# pyside6 and pyqt6 require python >=3.9
4648
- python-version: "3.8"
4749
qt-version: pyside6

qasync/__init__.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -833,29 +833,30 @@ def wrapper(*args, **kwargs):
833833

834834
return outer_decorator
835835

836-
837-
class QEventLoopPolicyMixin:
838-
def new_event_loop(self):
839-
return QEventLoop(QApplication.instance() or QApplication(sys.argv))
840-
841-
842-
class DefaultQEventLoopPolicy(
843-
QEventLoopPolicyMixin,
844-
asyncio.DefaultEventLoopPolicy,
845-
):
846-
pass
847-
848-
849836
@contextlib.contextmanager
850-
def _set_event_loop_policy(policy):
851-
old_policy = asyncio.get_event_loop_policy()
852-
asyncio.set_event_loop_policy(policy)
837+
def _use_qeventloop(loop_factory):
838+
app = QApplication.instance() or QApplication([sys.argv])
839+
if loop_factory is None:
840+
loop = QEventLoop(app)
841+
else:
842+
loop = loop_factory(app)
843+
try:
844+
old_loop = asyncio.get_event_loop()
845+
except RuntimeError: # No current event loop
846+
old_loop = None
847+
asyncio.set_event_loop(loop)
853848
try:
854-
yield
849+
yield loop
855850
finally:
856-
asyncio.set_event_loop_policy(old_policy)
857-
851+
loop.close()
852+
asyncio.set_event_loop(None)
858853

859-
def run(*args, **kwargs):
860-
with _set_event_loop_policy(DefaultQEventLoopPolicy()):
861-
return asyncio.run(*args, **kwargs)
854+
# A run function matching the signature of asyncio.run
855+
def run(main_coro, *, debug=None, loop_factory=None):
856+
"""
857+
Run the given coroutine using a QEventLoop.
858+
"""
859+
with _use_qeventloop(loop_factory) as loop:
860+
if debug is not None:
861+
loop.set_debug(debug)
862+
return loop.run_until_complete(main_coro)

0 commit comments

Comments
 (0)