Skip to content

Commit fb19109

Browse files
committed
gracefully shutdown when BLE device connect fails
1 parent 1e447cb commit fb19109

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

meshtastic/ble_interface.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ def __init__(
5353
self._receiveThread.start()
5454
logging.debug("Threads running")
5555

56+
self.client: Optional[BLEClient] = None
5657
try:
5758
logging.debug(f"BLE connecting to: {address if address else 'any'}")
58-
self.client: Optional[BLEClient] = self.connect(address)
59+
self.client = self.connect(address)
5960
logging.debug("BLE connected")
6061
except BLEInterface.BLEError as e:
6162
self.close()
@@ -207,7 +208,6 @@ def _sendToRadioImpl(self, toRadio):
207208
self.should_read = True
208209

209210
def close(self):
210-
atexit.unregister(self._exit_handler)
211211
try:
212212
MeshInterface.close(self)
213213
except Exception as e:
@@ -219,6 +219,7 @@ def close(self):
219219
self._receiveThread = None
220220

221221
if self.client:
222+
atexit.unregister(self._exit_handler)
222223
self.client.disconnect()
223224
self.client.close()
224225
self.client = None

0 commit comments

Comments
 (0)