Repository navigation
Fix #203: libusb sometimes cleaned up too early. - #227
Conversation
Each call to libusb1's get_backend returns a new _LibUSB object. When each _LibUSB object falls out of scope, it calls ends up calling libusb_exit() which deinitializes libusb, even if there are still references in scope. Practically speaking, pyusb seems to assume there's only one context active, so returning the same _LibUSB object on subsequent calls to get_backend should prevent there from being more than one call to libusb_exit() when backend objects go out of scope. This should fix errors where the libusb library was being used after libusb_exit() had been called.
|
This completely solves the access violation errors I'm getting on Windows with the current release version. |
For me as well (on Windows 10). I hope this can be merged soon. |
|
tossing in another "fixes libusb-1.0.dll 1.0.22 with windows10" |
|
I would like to apply this fix on top of v1.0.2 and redistribute it under that license.¹ The license was changed after v1.0.2 (BSD -> Apache, see #201), but development has halted, everyone's still using v1.0.2 and I don't want to force the license change downstream. So can I ask you to dual license your patch to allow it to be used under the 3-clause BSD license the project used before? ¹ I would be redistributing your patch as part of the liquidctl binaries for Windows. |
|
Yes @jonasmalacofilho I am happy to dual-license the patch under the previous BSD-3 license, and hereby do so. |
The patch for PyUSB successfully prevents access violation errors during
cleanup with libusb 1.0.22, but "some libusb_devices were leaked"
warnings can still be seen with LIBUSB_DEBUG=3.
Patch: 8041ec11b2c4 ("Fix #203: libusb sometimes cleaned up too early.")
Related: pyusb/pyusb#227 ("Fix #203: libusb sometimes cleaned up too early.")
Related: pyusb/pyusb#203 ("OSError with wxPython #203")
|
Thank you! FYI I can still see some "libusb_devices were leaked" warnings with |
|
Thank you for merging this and the other three PRs. |
|
yay! thats great - thanks @mcuee ! |
|
@mcuee can you get the pypi version bumped so this fix can be distributed :) |
|
I’ve done an awful job maintaining the project due to my day responsibilities. @mcuee , I can assign over the pypi project to you. |
|
@SimplicityGuy don't feel awful - you've done a great job getting it this far :) its really a wonderful library and very reliable! |
|
@SimplicityGuy |
|
To help the project a bit, I have cleaned up the issues list. |
|
I can help as well. |
|
@jonasmalacofilho added you. Please accept the invitation to be added. |
|
@mcuee thank you! |
I think the cause of #203 is each time libusb1.get_backend() is being called, a new _LibUSB backend object is being created and returned.
When the first of these goes out of scope and is finalized, it de-inits the underlying libusb1 library, invalidating any remaining backend object instances and calls made through them.
My fix is to assume that there is only going to be one _LibUSB backend object and cache it, returning it to subsequent libusb1.get_backend calls. This assumption mirrors the one made about _lib.