Skip to content

Commit 9461b0b

Browse files
authored
Create event loop only when necessary (#58)
1 parent abe4208 commit 9461b0b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

eq3bt/bleakconnection.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ def __init__(self, mac, iface):
3333
self._callbacks = {}
3434
self._notifyevent = asyncio.Event()
3535
self._notification_handle = None
36-
self._loop = asyncio.new_event_loop()
36+
37+
try:
38+
self._loop = asyncio.get_running_loop()
39+
except RuntimeError:
40+
self._loop = asyncio.new_event_loop()
41+
asyncio.set_event_loop(self._loop)
3742

3843
def __enter__(self):
3944
"""

0 commit comments

Comments
 (0)