Skip to content

Commit

Permalink
Merge pull request #281 from ales-erjavec/fixes/qasync-loop
Browse files Browse the repository at this point in the history
[FIX] Ensure qasync loop is set as running
  • Loading branch information
PrimozGodec committed Oct 13, 2023
2 parents 81f762b + 622fb4e commit 49a5f33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions orangecanvas/utils/asyncutils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import os
import asyncio
from concurrent import futures
from typing import Optional

from AnyQt.QtCore import QCoreApplication, QThread
import qasync


def get_event_loop() -> asyncio.AbstractEventLoop:
Expand Down Expand Up @@ -32,16 +32,16 @@ def get_event_loop() -> asyncio.AbstractEventLoop:
if loop is not None:
return loop

qt_api = os.environ.get("QT_API", "").lower()
if qt_api == "pyqt5":
os.environ["QT_API"] = "PyQt5"
elif qt_api == "pyside2":
os.environ["QT_API"] = "PySide2"
import qasync

if loop is None:
loop = qasync.QEventLoop(app)
# Do not use qasync.QEventLoop's default executor which uses QThread
# based pool and exhibits https://github.com/numpy/numpy/issues/11551
loop.set_default_executor(futures.ThreadPoolExecutor())
try:
# qasync>=0.24.2 no longer sets the running loop in QEventLoop
# constructor
get_running_loop()
except RuntimeError:
asyncio.events._set_running_loop(loop)
assert get_running_loop() is not None
return loop
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"requests-cache",
"pip>=18.0",
"dictdiffer",
"qasync",
"qasync>=0.10.0",
"importlib_metadata; python_version<'3.8'",
"packaging",
"numpy",
Expand Down

0 comments on commit 49a5f33

Please sign in to comment.