some fixes again
This commit is contained in:
@@ -173,12 +173,21 @@ class USBTransport:
|
||||
self._rx_thread = None
|
||||
|
||||
if self._handle is not None:
|
||||
self._handle.releaseInterface(self.INTERFACE)
|
||||
self._handle.close()
|
||||
# Always release AND close the handle, even if releaseInterface raises on
|
||||
# a vanished/changed device. Otherwise the handle leaks with the interface
|
||||
# still claimed, and every subsequent connect() fails forever with
|
||||
# "Failed to claim USB interface" (LIBUSB_ERROR_BUSY) — the device never
|
||||
# recovers after a hot-unplug/replug. close() releases the claim at the OS
|
||||
# level regardless, so reconnect can claim it again.
|
||||
with suppress(usb1.USBError):
|
||||
self._handle.releaseInterface(self.INTERFACE)
|
||||
with suppress(usb1.USBError):
|
||||
self._handle.close()
|
||||
self._handle = None
|
||||
|
||||
if self._ctx is not None:
|
||||
self._ctx.close()
|
||||
with suppress(usb1.USBError):
|
||||
self._ctx.close()
|
||||
self._ctx = None
|
||||
|
||||
logger.info("USB disconnected (serial=%s)", self.connected_serial)
|
||||
|
||||
Reference in New Issue
Block a user