Comments (6)
My guess is that the kernel releases the resources allocated by claim_interface
operation once the device is disconnected. If I am right, I think the only way to safely do the cleanup is after bug #64 lands, then at disconnect event, we can release the interface.
We can also try to reenumerate the device before call libusb_release_interface
to check if it is still there (inside the backend), but it feels hacky.
from pyusb.
What kernel and libusb version are you using? I tried to reproduce the problem but I couldn't. Could you please also elaborate more on how to reproduce this?
from pyusb.
Kernel is Centos 5, which is 2.6.18. I am currently using Libusb 1.0.19. But as I stated earlier:
The exception happens every time when the device is in a certain configuration, but does
not happen when the device is in another configuration.
This may be difficult for you to reproduce, since you don't have the device, and in my case it was specific to a certain configuration on that device.
My suggestion would be to catch and ignore the error in release_interface. If you are confident that your code has a correct device (it worked earlier) and owns the interface that it is attempting to release, then the code should be fine, and an error of "No Such Device" could be confidently ignored.
I can and will test anything you need. Let me know.
from pyusb.
Could you please try this patch and check if the error is gone?
From 8ab3b5b991b859aaf4e2b6d1813fbdbadfb50d5d Mon Sep 17 00:00:00 2001
From: Wander Lairson Costa <[email protected]>
Date: Sun, 18 Jan 2015 10:30:48 -0200
Subject: [PATCH] core: Handle exceptions when releasing the interfaces.
At object destruction, claimed interfaces are released. If the device
is disconnected, the call to release_interface may fail and raise an
exception.
closes #84.
---
usb/core.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/usb/core.py b/usb/core.py
index 6174e93..50446db 100644
--- a/usb/core.py
+++ b/usb/core.py
@@ -220,7 +220,12 @@ class _ResourceManager(object):
def release_all_interfaces(self, device):
claimed = copy.copy(self._claimed_intf)
for i in claimed:
- self.managed_release_interface(device, i)
+ try:
+ self.managed_release_interface(device, i)
+ except USBError:
+ # Ignore errors when releasing the interfaces
+ # When the device is disconnected, the call may fail
+ pass
def dispose(self, device, close_handle = True):
self.release_all_interfaces(device)
--
1.9.1
from pyusb.
Verified this patch prevents the exception from getting back up to the del() method and subsequently being reported via stderr.
from pyusb.
Thanks for testing the patch.
from pyusb.
Related Issues (20)
- reset device lead to Operation timed out HOT 2
- Typo in Documentation HOT 1
- Codestyle: Type Hints (PEP 484) HOT 3
- libusb stress_mt.c conversion to pyusb HOT 16
- usb.core.USBError: [Errno 22] Invalid parameter while using dev.ctrl_transfer in Windows HOT 1
- Closed
- usb.core.USBError: [Errno 19] No such device (mac os M1) HOT 1
- Incorrect usage of intf variable in pyusb tutorial for finding OUT endpoint HOT 1
- Usb python
- USB
- PyUSB does not seem to be properly installed one one computer HOT 3
- `bytearray()` buffers in addition to `array.array`
- There was an error in the subpackage sending, the first normal sending and the second direct error report, the agreed code c is fine HOT 5
- USB (-ENOENT) (-2) wireshark Error
- usb.core.NoBackendError: No backend available
- [Errno 13] Access denied (insufficient permissions)
- Very laggy when reading data from device HOT 2
- usb.core.USBError: [Errno 5] Input/Output Error when trying to send feature report to device HOT 1
- Timeout Problem with Raspberry Pi 5 USB Port Output HOT 1
- No Backend available MAC HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyusb.