Repository navigation
Closed
Labels
Description
If I try to find the USB devices in a wxPython window, I get the following error:
Exception ignored in: <bound method _AutoFinalizedObjectBase.__del__ of <usb.backend.libusb1._Device object at 0x04307210>>
Traceback (most recent call last):
File "C:\Users\guest\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\_objfinalizer.py", line 84, in __del__
self.finalize()
File "C:\Users\guest\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\_objfinalizer.py", line 144, in finalize
self._finalizer()
File "C:\Users\guest\AppData\Local\Programs\Python\Python36-32\lib\weakref.py", line 548, in __call__
return info.func(*info.args, **(info.kwargs or {}))
File "C:\Users\guest\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\_objfinalizer.py", line 104, in _do_finalize_object_ref
obj._do_finalize_object()
File "C:\Users\guest\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\_objfinalizer.py", line 71, in _do_finalize_object
self._finalize_object()
File "C:\Users\guest\AppData\Local\Programs\Python\Python36-32\lib\site-packages\usb\backend\libusb1.py", line 604, in _finalize_object
_lib.libusb_unref_device(self.devid)
OSError: exception: access violation writing 0x00000014
^C
Here is some simple code that can create the error.
import wx
import usb
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Example")
panel = wx.Panel(self, wx.ID_ANY)
sizer = wx.BoxSizer(wx.VERTICAL)
button = wx.Button(panel, label="Run test()")
button.Bind(wx.EVT_BUTTON, self.test)
sizer.Add(button, 0, wx.ALL|wx.CENTER, 5)
panel.SetSizer(sizer)
def test(self, event):
valueList = []
devices = usb.core.find(find_all=True)
for config in devices:
valueList.append((config.idVendor, config.idProduct))
print(valueList)
event.Skip()
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()
To produce the error, press the button "Run test()" in the frame that appears after running the code.
Activity
JoshMayberry commentedon Jun 13, 2018
I also get a similar error by running the show_devices() function in usb.core
This code is what produces this error.
mcuee commentedon Aug 1, 2018
libusb/libusb#412
Issue reported here.
mcuee commentedon Aug 1, 2018
mcuee commentedon Aug 1, 2018
Temporary workaround is to go back to libusb-1.0.21 where this issues does not manifest itself.
mcuee commentedon Aug 1, 2018
Or you can use libusb0 backend (libusb-win32). Take note libusb-win32 will only list the device which uses libusb-win32 compatible driver (libusb0.sys or libusbk.sys).
dickens commentedon Aug 3, 2018
See comment in libusb/libusb#412. This is not a libusb issue.
chisaipete commentedon Aug 27, 2018
So, it looks like this is a pyusb issue, is there any word on a fix?
JoshMayberry commentedon Dec 13, 2018
@mcuee How are things going with a fix for this error?
Fix pyusb#203: libusb sometimes cleaned up too early.
Patch PyUSB and upgrade libusb to 1.0.22 on Windows builds
mcuee commentedon Nov 30, 2019
Maybe the following can help.
Ref: eblot/pyftdi#121
eblot commented:
I found a weird behaviour in pyusb: when the port is indirectly closed right after the port is open, some kind of race condition in pyusb/libusb lets it to re-open the closed device to perform the cleanup action, which triggers a native exception in libusb. This has been worked around in the latest PyFtdi patch version (v0.30.1), so that no cleanup action is performed when the existing pyusb handle is not longer existing. This prevents the pyusb resource manager to re-open the device in such event.mcuee commentedon Dec 7, 2019
With the latest git, it seems to be okay, with latest libusb Windows.
mcuee commentedon Dec 7, 2019
No issues with wxusb.py either when I press the button.
mcuee commentedon Dec 7, 2019
@JoshMayberry
Probably #227 fixed this issue.
Please check on your side. Thanks.
JoshMayberry commentedon Dec 10, 2019
@mcuee
Thank you for remembering this issue after so long. You all are doping a wonderful job! And congratulations for finding the fix!
After using the latest version from the github, the problem was solved (No OSError when I ran the script I provided at the top of this issue).
This fix is not, however, in the latest version on pypi.org.
jonasmalacofilho commentedon Dec 10, 2019
@JoshMayberry
I understand (including from my own experience) that this is an annoying issue for downstream projects. I'll try to get a release ready soon, even if some other issues end up missing the cut.
akbyrd commentedon May 18, 2020
Any word on a release?
jonasmalacofilho commentedon May 18, 2020
I delayed the release because a few (unconfirmed but suspect) unrelated issues have surfaced.