Skip to content

Commit e7f605d

Browse files
pi-anldpgeorge
authored andcommitted
aioble/device.py: Always create connection._event.
If the client disconnects immediately after connection, the irq can be run before the initial connect handler has finished.
1 parent f0b6832 commit e7f605d

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

micropython/bluetooth/aioble/aioble/device.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def __init__(self, device):
164164

165165
# This event is fired by the IRQ both for connection and disconnection
166166
# and controls the device_task.
167-
self._event = None
167+
self._event = asyncio.ThreadSafeFlag()
168168

169169
# If we're waiting for a pending MTU exchange.
170170
self._mtu_event = None
@@ -207,9 +207,6 @@ async def device_task(self):
207207
t._task.cancel()
208208

209209
def _run_task(self):
210-
# Event will be already created this if we initiated connection.
211-
self._event = self._event or asyncio.ThreadSafeFlag()
212-
213210
self._task = asyncio.create_task(self.device_task())
214211

215212
async def disconnect(self, timeout_ms=2000):

0 commit comments

Comments
 (0)