Skip to content

Commit

Permalink
Merge pull request #83 from veractor/fix-python311
Browse files Browse the repository at this point in the history
Fix qasync.run in Python 3.11
  • Loading branch information
hosaka authored Aug 30, 2023
2 parents 28c6599 + c46edb1 commit 0167a39
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions qasync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,9 +330,11 @@ class _QEventLoop:
If the event loop shall be used with an existing and already running QApplication
it must be specified in the constructor via already_running=True
In this case the user is responsible for loop cleanup with stop() and close()
The set_running_loop parameter is there for backwards compatibility and does nothing.
"""

def __init__(self, app=None, set_running_loop=True, already_running=False):
def __init__(self, app=None, set_running_loop=False, already_running=False):
self.__app = app or QApplication.instance()
assert self.__app is not None, "No QApplication has been instantiated"
self.__is_running = False
Expand All @@ -350,9 +352,6 @@ def __init__(self, app=None, set_running_loop=True, already_running=False):
assert self.__app is not None
super().__init__()

if set_running_loop:
asyncio.events._set_running_loop(self)

# We have to set __is_running to True after calling
# super().__init__() because of a bug in BaseEventLoop.
if already_running:
Expand All @@ -363,6 +362,9 @@ def __init__(self, app=None, set_running_loop=True, already_running=False):
self._before_run_forever()
self.__app.aboutToQuit.connect(self._after_run_forever)

# for asyncio to recognize the already running loop
asyncio.events._set_running_loop(self)

def run_forever(self):
"""Run eventloop forever."""

Expand Down

0 comments on commit 0167a39

Please sign in to comment.