From 9461b0bb896f0c5a7fb37640ec57d9bfd5cfb450 Mon Sep 17 00:00:00 2001 From: Teemu R Date: Thu, 8 Sep 2022 22:18:57 +0200 Subject: [PATCH] Create event loop only when necessary (#58) --- eq3bt/bleakconnection.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/eq3bt/bleakconnection.py b/eq3bt/bleakconnection.py index 3624ccc..d0d040d 100644 --- a/eq3bt/bleakconnection.py +++ b/eq3bt/bleakconnection.py @@ -33,7 +33,12 @@ def __init__(self, mac, iface): self._callbacks = {} self._notifyevent = asyncio.Event() self._notification_handle = None - self._loop = asyncio.new_event_loop() + + try: + self._loop = asyncio.get_running_loop() + except RuntimeError: + self._loop = asyncio.new_event_loop() + asyncio.set_event_loop(self._loop) def __enter__(self): """