Asyncio updates for gui connections
Workaround, ensure asyncio event loop is launched on each thread.
# See the License for the specific language governing permissions and
# limitations under the License.
#
+import asyncio
+
from collections import namedtuple
from threading import Lock
@@ -403,6 +405,11 @@ class Enclosure:
if gui_id in self.GUIs:
# TODO: Close it?
pass
+ try:
+ asyncio.get_event_loop()
+ except RuntimeError:
+ asyncio.set_event_loop(asyncio.new_event_loop())
+
self.GUIs[gui_id] = GUIConnection(gui_id, self.global_config,
self.callback_disconnect, self)
LOG.debug("Heard announcement from gui_id: {}".format(gui_id))
@@ -599,6 +606,11 @@ class GUIWebsocketHandler(WebSocketHandler):
def write_message(self, *arg, **kwarg):
""" Wraps WebSocketHandler.write_message() with a lock. """
+ try:
+ asyncio.get_event_loop()
+ except RuntimeError:
+ asyncio.set_event_loop(asyncio.new_event_loop())
+
with write_lock:
super().write_message(*arg, **kwarg)
