BLESession.close: Improve close handler

Guard peripheral disconnect handling with lock not to race with other
peripheral operations. After disconnect, set None to the peripheral
reference to ensure no use.
This commit is contained in:
Shin'ichiro Kawasaki
2020-07-25 10:24:48 +09:00
parent dd194ae1c2
commit fe86e485f4

View File

@@ -433,7 +433,9 @@ class BLESession(Session):
self.status = self.DONE
if self.perip:
logger.info(f"disconnect to BLE peripheral: {self.perip}")
self.perip.disconnect()
with self.lock:
self.perip.disconnect()
self.perip = None
def __del__(self):
self.close()