Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions micropython/bluetooth/aioble/aioble/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,21 @@ def write(self, data, send_update=False):
else:
ble.gatts_write(self._value_handle, data, send_update)

# When the a capture-enabled characteristic is created, create the
# When a capture-enabled characteristic is created, create the
# necessary events (if not already created).
# Guard on _capture_task (not _capture_queue) to match _server_shutdown()
# which guards on _capture_task. This ensures partial teardown (task gone
# but queue remains) self-heals instead of silently no-oping.
@staticmethod
def _init_capture():
if hasattr(BaseCharacteristic, "_capture_queue"):
if hasattr(BaseCharacteristic, "_capture_task"):
return

# Clean up any partial state from incomplete shutdown
for attr in ("_capture_queue", "_capture_write_event", "_capture_consumed_event"):
try:
delattr(BaseCharacteristic, attr)
except AttributeError:
pass
BaseCharacteristic._capture_queue = deque((), _WRITE_CAPTURE_QUEUE_LIMIT)
BaseCharacteristic._capture_write_event = asyncio.ThreadSafeFlag()
BaseCharacteristic._capture_consumed_event = asyncio.ThreadSafeFlag()
Expand Down
Loading