Skip to content

Commit

Permalink
Only init already_running QEventLoops as running
Browse files Browse the repository at this point in the history
When a QEventLoop is not already running, it should not set itself as
the running loop on construction, and should do so exclusively when
actually ran, i.e. in run_forever. Already running QEventLoops OTOH
should always set themselves as the running loop on construction.

This renders the set_running_loop constructor parameter obsolete. It is
kept for compatibility.
  • Loading branch information
veractor committed Jul 15, 2023
1 parent 28c6599 commit c46edb1
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 c46edb1

Please sign in to comment.