Skip to content

Commit 9ee34a4

Browse files
committed
Support Python 3.14.
1 parent de293ac commit 9ee34a4

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
@@ -830,29 +830,30 @@ def wrapper(*args, **kwargs):
830830

831831
return outer_decorator
832832

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

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

0 commit comments

Comments
 (0)