From 46601dcfbc399cd7a28ed97bedf8bdba93ed51a4 Mon Sep 17 00:00:00 2001
From: Beinan Li
Date: Wed, 30 Jun 2021 10:16:37 +0800
Subject: [PATCH 1/2] fixed: exception about missing event loop in threadpool
when other processes create their own acync event loop
---
waapi/client/client.py | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/waapi/client/client.py b/waapi/client/client.py
index 0fe41c0..ae263f9 100644
--- a/waapi/client/client.py
+++ b/waapi/client/client.py
@@ -63,18 +63,22 @@ def __init__(self,
self._callback_executor = callback_executor
self._client_thread = None
""":type: Thread"""
-
- self._loop = asyncio.get_event_loop()
- if not self._loop.is_running():
- if not self._loop.is_closed():
+ # ++++[community fix]
+ try:
+ self._loop = asyncio.get_event_loop()
+ except Exception as e:
+ print(e)
+ self._loop = None
+ if not self._loop or not self._loop.is_running():
+ if self._loop and not self._loop.is_closed():
self._loop.close()
+ # ----[community fix]
if platform == 'win32':
# Prefer the ProactorEventLoop event loop on Windows
self._loop = asyncio.ProactorEventLoop()
else:
self._loop = asyncio.new_event_loop()
asyncio.set_event_loop(self._loop)
-
self._decoupler = None
""":type: AutobahnClientDecoupler"""
From 0b0ef8c8668e1d54ca27582d2827efdf7e5ca76a Mon Sep 17 00:00:00 2001
From: Beinan Li
Date: Wed, 30 Jun 2021 11:43:25 +0800
Subject: [PATCH 2/2] closed event loop on disconnection to secure safe
reentrance
---
waapi/client/client.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/waapi/client/client.py b/waapi/client/client.py
index ae263f9..8ae0c91 100644
--- a/waapi/client/client.py
+++ b/waapi/client/client.py
@@ -129,9 +129,14 @@ def disconnect(self):
# Create a new loop for upcoming uses
if asyncio.get_event_loop().is_closed():
asyncio.set_event_loop(asyncio.new_event_loop())
-
+ # ++++[community fix]
+ self._loop.close()
+ # ----[community fix]
return True
+ # ++++[community fix]
+ self._loop.close()
+ # ----[community fix]
# Only the caller that truly caused the disconnection return True
return False