Skip to content

Commit 9297732

Browse files
committed
fix possible race with thread shutdown. somehow receiveThread can be null
1 parent a6c3e5c commit 9297732

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

meshtastic/ble_interface.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def _receiveFromRadioImpl(self):
196196

197197
def _sendToRadioImpl(self, toRadio):
198198
b = toRadio.SerializeToString()
199-
if b:
199+
if b and self.client: # we silently ignore writes while we are shutting down
200200
logging.debug(f"TORADIO write: {b.hex()}")
201201
try:
202202
self.client.write_gatt_char(
@@ -219,10 +219,11 @@ def close(self):
219219

220220
if self._want_receive:
221221
self.want_receive = False # Tell the thread we want it to stop
222-
self._receiveThread.join(
223-
timeout=2
224-
) # If bleak is hung, don't wait for the thread to exit (it is critical we disconnect)
225-
self._receiveThread = None
222+
if self._receiveThread:
223+
self._receiveThread.join(
224+
timeout=2
225+
) # If bleak is hung, don't wait for the thread to exit (it is critical we disconnect)
226+
self._receiveThread = None
226227

227228
if self.client:
228229
atexit.unregister(self._exit_handler)

0 commit comments

Comments
 (0)