From 6d8f52d918e2e84129d769e9c0e31a54c11971d1 Mon Sep 17 00:00:00 2001 From: zerotypic Date: Wed, 11 Nov 2020 16:03:34 +0800 Subject: [PATCH] Added optional argument to QEventLoop constructor to indicate the event loop is already running. --- qasync/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/qasync/__init__.py b/qasync/__init__.py index ff0a890..874274a 100644 --- a/qasync/__init__.py +++ b/qasync/__init__.py @@ -257,7 +257,7 @@ class _QEventLoop: ... loop.run_until_complete(xplusy(2, 2)) """ - def __init__(self, app=None, set_running_loop=True): + def __init__(self, app=None, set_running_loop=True, already_running=False): self.__app = app or QApplication.instance() assert self.__app is not None, 'No QApplication has been instantiated' self.__is_running = False @@ -278,6 +278,11 @@ def __init__(self, app=None, set_running_loop=True): 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: + self.__is_running = True + def run_forever(self): """Run eventloop forever.""" self.__is_running = True