OSError with wxPython
See original GitHub issueIf 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.
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (10 by maintainers)
Top Results From Across the Web
wxpython install error
7/site-packages/wx folder. It is a binary extension module, not Python code. The ImportError indicates that either it, or something that it is ...
Read more >wxPython failing to install for Python 3.11.0
When I try to install wxPython: pip install wxpython , the process runs for a long time and it causes the system to...
Read more >"ActiveX_PDFWindow.py" module failed.
You received this message because you are subscribed to the Google Groups "wxPython-users" group. To unsubscribe from this group and stop receiving emails...
Read more >#2647 (mac OSX - wxpython 3 (64 bit) - ps.map fails to generate ...
Trying to generate a simple pdf (single raster map + legend) the gui wx map ... line 1335, in _execute_child raise child_exception OSError:...
Read more >Python 101 - Exception Handling
OSError - Raised when a function returns a system-related error. RuntimeError - Raised when an error is detected that doesn't fall in any...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
Maybe the following can help.
Ref: https://github.com/eblot/pyftdi/issues/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.