From 3e9c49e57a0de4a5efa57fa5065be73d1ac9bd35 Mon Sep 17 00:00:00 2001 From: zerotypic Date: Tue, 10 Nov 2020 15:53:48 +0800 Subject: [PATCH] Added optional argument to QEventLoop constructor to indicate the event loop is already running. --- asyncqt/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/asyncqt/__init__.py b/asyncqt/__init__.py index 38f7445..1880983 100644 --- a/asyncqt/__init__.py +++ b/asyncqt/__init__.py @@ -255,7 +255,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 @@ -276,6 +276,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