Skip to content

Commit bddac58

Browse files
Merge pull request CabbageDevelopment#15 from zerotypic/evloop_already_running
Optional argument to QEventLoop constructor for already running loops
2 parents d9cd56b + 6d8f52d commit bddac58

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

qasync/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class _QEventLoop:
271271
... loop.run_until_complete(xplusy(2, 2))
272272
"""
273273

274-
def __init__(self, app=None, set_running_loop=True):
274+
def __init__(self, app=None, set_running_loop=True, already_running=False):
275275
self.__app = app or QApplication.instance()
276276
assert self.__app is not None, 'No QApplication has been instantiated'
277277
self.__is_running = False
@@ -292,6 +292,11 @@ def __init__(self, app=None, set_running_loop=True):
292292
if set_running_loop:
293293
asyncio.events._set_running_loop(self)
294294

295+
# We have to set __is_running to True after calling
296+
# super().__init__() because of a bug in BaseEventLoop.
297+
if already_running:
298+
self.__is_running = True
299+
295300
def run_forever(self):
296301
"""Run eventloop forever."""
297302
self.__is_running = True

0 commit comments

Comments
 (0)