Comments (58)
Thanks for the extensive testing and debugging.
The following debug log seems to be a bit suspicious. Is it possible that only the default context was detroyed and not the second second context?
One particularity of python-libusb1 is that my code never uses the default context, because this seemed the sane thing to do, and it was mapping very well in the object world. I suspect this may differ from most uses, and could cause unusual codepaths to be exercised. Could the windows backend accidentally rely on this ?
The default context destruction triggering warnings about still-referenced devices leaked libusb_devices
looks to me as another hint that there may be some confusion about the context.
from python-libusb1.
...and I just noticed that your code calls __get_handle
twice (once in write
and once in read
). This should explain the duplicate libusb_get_device_list
call. It does not exclude an iterator lifetime issue, so I will poke a bit more at this.
from python-libusb1.
Just wondering if python-libusb1 has some debug logging feature which I can use to debug further.
Unfortunately, no, there isn't. This said, I'm more and more convinced that you are somehow hitting a garbage collection issue, and these are quite sensitive to things like the timing in which things occur, and adding logs could push things over the edge into the "it's working again" order.
I've re-read more carefully the libusb debugging output, and here is how I would summarize and group it:
usb1.USBContext()
[ 0.000344] [0000507c] libusb: debug [libusb_init] libusb v1.0.24.11650
print("write:", usb.write(msg))
[ 0.013124] [0000507c] libusb: debug [libusb_get_device_list]
[ 0.053055] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.053428] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.053668] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.053980] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.054248] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.054456] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.054770] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.055084] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.055169] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.055247] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.5
[ 0.055298] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.055345] [0000507c] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.055391] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.055531] [0000507c] libusb: debug [libusb_open] open 1.8
[ 0.055636] [0000507c] libusb: debug [libusb_claim_interface] interface 0
...
[ 0.057231] [0000507c] libusb: debug [libusb_release_interface] interface 0
[ 0.057314] [0000507c] libusb: debug [libusb_close]
write: True
print("read:", usb.read())
[ 0.057621] [0000507c] libusb: debug [libusb_get_device_list]
[ 0.095349] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.095506] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.095647] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.095973] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.096141] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.096268] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.096431] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.096641] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.096689] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.096733] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.5
[ 0.096777] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.096821] [0000507c] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.096865] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.096940] [0000507c] libusb: debug [libusb_open] open 1.8
[ 0.097032] [0000507c] libusb: debug [libusb_claim_interface] interface 0
...
[ 0.127214] [0000507c] libusb: debug [libusb_release_interface] interface 0
[ 0.127515] [0000507c] libusb: debug [libusb_close]
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
usb.close()
[ 0.128372] [0000507c] libusb: debug [libusb_exit]
[ 0.133276] [0000507c] libusb: warning [libusb_exit] device 1.8 still referenced
[ 0.133487] [0000507c] libusb: warning [libusb_exit] device 1.0 still referenced
interpreter exit (?):
[ 0.137786] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.8
Exception ignored in: <function USBDevice.__del__ at 0x000001BD8F7A8820>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1778, in __del__
self.close()
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1790, in close
self.__libusb_unref_device(self.device_p)
OSError: exception: access violation writing 0x0000000000000024
After libusb_close
calls, the 7th libusb_unref_device
does not happen, but nothing should be left referencing it. Could you try adding gc.collect()
after both the write()
and read()
calls ? Hopefully this should make these calls appear, and may resolve the access violation.
usb.close()
internal logic is as follows:
- wait for any concurrent code to leave any of the methods which require a valid context (this only matters for multi-threaded processes)
- unregister any present hostplug callback
- close any closable object obtained from this context. Relevant here is that it calls
USBDevice.close
, whose logic is:- close any
USBDeviceHandle
obtained from this device - call
libusb_unref_device
- free any associated descriptor memory
- mark the device as not to be closed again
- close any
- call
libusb_exit
But in the above we can see that USBDevice.close
, called from .__del__
(so not by USBContext.close
but by the garbage collector) and after libusb_exit
. Also, because libusb_unref_device
is actually called it means mark the device as not to be closed again
did not happen.
So I believe what is happening here may be that python, seeing this USBDevice
being left with no reference left since write
returned, is removing it from USBContext.__close_set
(which is a weak set, so as to no prevent early garbage collection), but it somehow does no destroy it just yet: at this point, the USBDevice
instance is left in limbo, not reachable by the USBContext
instance, but not destroyed either. And eventually python's garbage collector runs (for example during interpreter shutdown), and bam, access violation.
So far I do not know how I will reliably fix this. Switching to a strong set
for USBContext.__close_set
would cause memory leaks for long-running applications which may open/close devices a lot (without closing the context). An alternative would be to trigger the garbage collector in USBContext._exit
to try to make it get rid of anything it may have pulled out of USBContext.__close_set
but not have destroyed yet, and it is not a nice solution and I have no idea how reliable it would be in practice.
from python-libusb1.
This error is a bit weird: visibly this happens in write()
before it returns, and the error is that handle_events
does not get any event to handle, and hence it blocks forever (just waking up every 60s). As you are not using any async transfers, I suspect these calls are the ones done internally to libusb (as synchronous transfers are actually based on async transfers + a blocking handle_events
call, internally to libusb). Maybe there was something wrong with the device at that point ?
Checking this, I did found a bug with my change, but it should be unrelated to this hang (it was not possible to open the same device more than once). I fixed it, and tested a minimally modified version of you test code (only changing vendor id and device id to match those used in python-functionfs/examples/usbcat/device.py) and it is working on both win10 (with WinUSB driver attached to my pizero running usbcat/device.py) and linux.
Note that usbcat is not a loopback test but a bidirectional pipe (like netcat). As I did not provide any input to it, read
s always return an empty string. I think this does not change how representative this test is.
code
import usb1
class USB:
"""USB class that handles IO operation with USB device
ENDPOINT_IN: device-to-host, ENDPOINT_OUT: host-to-device"""
# read size chunk
READ_CHUNK = 1024
def __init__(self, pid: hex, vid: hex, endpoint_in: hex, endpoint_out: hex) -> None:
self.endpoint_in = endpoint_in
self.endpoint_out = endpoint_out
self.pid = pid
self.vid = vid
self.context = usb1.USBContext()
def is_connected(self) -> bool:
"""Check if specified device is connected"""
with usb1.USBContext() as context:
for device in context.getDeviceIterator(skip_on_error=True):
if device.getVendorID() == self.vid and device.getProductID() == self.pid:
return True
def open(self) -> bool:
"""Open USB and initialize interface"""
try:
self.context.open()
return True
except Exception as err:
print("open device error:", err)
return False
def __get_handle(self):
"""return handle object"""
return self.context.openByVendorIDAndProductID(self.vid, self.pid)
def close(self) -> bool:
"""Close USB"""
print("Closing USB")
try:
self.context.close()
print("Close handle successfully")
return True
except Exception as err:
print("Close handle error:", err)
return False
def write(self, msg: bytearray, timeout: int = 0) -> bool:
"""write an specific msg to device"""
handle = self.__get_handle()
if not handle:
return False
try:
with handle.claimInterface(0):
bytes_written = handle.bulkWrite(
self.endpoint_out, msg, timeout)
bytes_written == len(msg)
print("Number of bytes written: ", bytes_written)
return True
except Exception as err:
print("write error", err)
#handle.close()
return False
def read(self, timeout: int = 10) -> bytearray:
"""read data from the device"""
data = bytearray()
handle = self.__get_handle()
if not handle:
return False
try:
with handle.claimInterface(0):
while True:
try:
data += handle.bulkRead(self.endpoint_in,
self.READ_CHUNK, timeout)
except usb1.USBErrorTimeout:
break
except Exception as err:
print("read error", err)
return None
handle.close()
return data
def __del__(self):
print("Calling closing method to delete self")
self.close()
if __name__ == '__main__':
VENDOR_ID = 0x1d6b
PRODUCT_ID = 0x0104
ENDPOINT_IN = 0x81
ENDPOINT_OUT = 0x01
usb = USB(PRODUCT_ID, VENDOR_ID, ENDPOINT_IN, ENDPOINT_OUT)
#print(usb.is_connected())
msg = 100 * bytearray(b"B")
if usb.open():
print("write:", usb.write(msg))
print("read:", usb.read())
# error after adding this line
usb.close()
linux output (LIBUSB_DEBUG=4)
$ sudo LIBUSB_DEBUG=4 ../vpy3/bin/python readwrite.py
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000011] [00016670] libusb: debug [libusb_init] created default context
[ 0.000018] [00016670] libusb: debug [libusb_init] libusb v1.0.24.11584
[ 0.000028] [00016670] libusb: debug [get_kernel_version] reported kernel version is 5.10.0-8-amd64
[ 0.000059] [00016670] libusb: debug [op_init] found usbfs at /dev/bus/usb
[ 0.000061] [00016670] libusb: debug [op_init] max iso packet length is (likely) 98304 bytes
[ 0.000065] [00016670] libusb: debug [op_init] sysfs is available
[ 0.000417] [00016671] libusb: debug [linux_udev_event_thread_main] udev event thread entering
[ 0.002350] [00016670] libusb: debug [linux_get_device_address] getting address for device: usb3 detached: 0
[ 0.002355] [00016670] libusb: debug [linux_get_device_address] scan usb3
[ 0.002384] [00016670] libusb: debug [linux_get_device_address] bus=3 dev=1
[ 0.002386] [00016670] libusb: debug [linux_enumerate_device] busnum 3 devaddr 1 session_id 769
[ 0.002388] [00016670] libusb: debug [linux_enumerate_device] allocating new device for 3/1 (session 769)
[ 0.002508] [00016670] libusb: debug [linux_get_device_address] getting address for device: usb4 detached: 0
[ 0.002511] [00016670] libusb: debug [linux_get_device_address] scan usb4
[ 0.002538] [00016670] libusb: debug [linux_get_device_address] bus=4 dev=1
[ 0.002540] [00016670] libusb: debug [linux_enumerate_device] busnum 4 devaddr 1 session_id 1025
[ 0.002543] [00016670] libusb: debug [linux_enumerate_device] allocating new device for 4/1 (session 1025)
[ 0.002607] [00016670] libusb: debug [linux_get_device_address] getting address for device: usb1 detached: 0
[ 0.002610] [00016670] libusb: debug [linux_get_device_address] scan usb1
[ 0.002641] [00016670] libusb: debug [linux_get_device_address] bus=1 dev=1
[ 0.002644] [00016670] libusb: debug [linux_enumerate_device] busnum 1 devaddr 1 session_id 257
[ 0.002659] [00016670] libusb: debug [linux_enumerate_device] allocating new device for 1/1 (session 257)
[ 0.002726] [00016670] libusb: debug [linux_get_device_address] getting address for device: 1-12 detached: 0
[ 0.002730] [00016670] libusb: debug [linux_get_device_address] scan 1-12
[ 0.002745] [00016670] libusb: debug [linux_get_device_address] bus=1 dev=4
[ 0.002748] [00016670] libusb: debug [linux_enumerate_device] busnum 1 devaddr 4 session_id 260
[ 0.002751] [00016670] libusb: debug [linux_enumerate_device] allocating new device for 1/4 (session 260)
[ 0.002791] [00016670] libusb: debug [linux_get_parent_info] dev 0x208a9d0 (1-12) has parent 0x20a4e90 (usb1) port 12
[ 0.002874] [00016670] libusb: debug [linux_get_device_address] getting address for device: 1-13 detached: 0
[ 0.002877] [00016670] libusb: debug [linux_get_device_address] scan 1-13
[ 0.002890] [00016670] libusb: debug [linux_get_device_address] bus=1 dev=5
[ 0.002893] [00016670] libusb: debug [linux_enumerate_device] busnum 1 devaddr 5 session_id 261
[ 0.002895] [00016670] libusb: debug [linux_enumerate_device] allocating new device for 1/5 (session 261)
[ 0.002908] [00016670] libusb: debug [linux_get_parent_info] dev 0x20a5920 (1-13) has parent 0x20a4e90 (usb1) port 13
[ 0.002949] [00016670] libusb: debug [linux_get_device_address] getting address for device: 1-3 detached: 0
[ 0.002952] [00016670] libusb: debug [linux_get_device_address] scan 1-3
[ 0.002967] [00016670] libusb: debug [linux_get_device_address] bus=1 dev=2
[ 0.002970] [00016670] libusb: debug [linux_enumerate_device] busnum 1 devaddr 2 session_id 258
[ 0.002973] [00016670] libusb: debug [linux_enumerate_device] allocating new device for 1/2 (session 258)
[ 0.002989] [00016670] libusb: debug [linux_get_parent_info] dev 0x208bc20 (1-3) has parent 0x20a4e90 (usb1) port 3
[ 0.003032] [00016670] libusb: debug [linux_get_device_address] getting address for device: 1-4 detached: 0
[ 0.003035] [00016670] libusb: debug [linux_get_device_address] scan 1-4
[ 0.003050] [00016670] libusb: debug [linux_get_device_address] bus=1 dev=3
[ 0.003053] [00016670] libusb: debug [linux_enumerate_device] busnum 1 devaddr 3 session_id 259
[ 0.003055] [00016670] libusb: debug [linux_enumerate_device] allocating new device for 1/3 (session 259)
[ 0.003069] [00016670] libusb: debug [linux_get_parent_info] dev 0x208be70 (1-4) has parent 0x20a4e90 (usb1) port 4
[ 0.003110] [00016670] libusb: debug [linux_get_device_address] getting address for device: 1-9 detached: 0
[ 0.003113] [00016670] libusb: debug [linux_get_device_address] scan 1-9
[ 0.003141] [00016670] libusb: debug [linux_get_device_address] bus=1 dev=13
[ 0.003157] [00016670] libusb: debug [linux_enumerate_device] busnum 1 devaddr 13 session_id 269
[ 0.003160] [00016670] libusb: debug [linux_enumerate_device] allocating new device for 1/13 (session 269)
[ 0.003174] [00016670] libusb: debug [linux_get_parent_info] dev 0x208c0c0 (1-9) has parent 0x20a4e90 (usb1) port 9
[ 0.003219] [00016670] libusb: debug [linux_get_device_address] getting address for device: 1-9.3 detached: 0
[ 0.003222] [00016670] libusb: debug [linux_get_device_address] scan 1-9.3
[ 0.003238] [00016670] libusb: debug [linux_get_device_address] bus=1 dev=14
[ 0.003241] [00016670] libusb: debug [linux_enumerate_device] busnum 1 devaddr 14 session_id 270
[ 0.003243] [00016670] libusb: debug [linux_enumerate_device] allocating new device for 1/14 (session 270)
[ 0.003257] [00016670] libusb: debug [linux_get_parent_info] dev 0x208c2f0 (1-9.3) has parent 0x208c0c0 (1-9) port 3
[ 0.003296] [00016670] libusb: debug [linux_get_device_address] getting address for device: usb2 detached: 0
[ 0.003299] [00016670] libusb: debug [linux_get_device_address] scan usb2
[ 0.003314] [00016670] libusb: debug [linux_get_device_address] bus=2 dev=1
[ 0.003317] [00016670] libusb: debug [linux_enumerate_device] busnum 2 devaddr 1 session_id 513
[ 0.003320] [00016670] libusb: debug [linux_enumerate_device] allocating new device for 2/1 (session 513)
[ 0.003378] [00016670] libusb: debug [usbi_add_event_source] add fd 5 events 1
[ 0.003383] [00016670] libusb: debug [usbi_io_init] using timer for timeouts
[ 0.003386] [00016670] libusb: debug [usbi_add_event_source] add fd 6 events 1
[ 0.003455] [00016670] libusb: debug [libusb_get_device_list]
[ 0.003462] [00016670] libusb: debug [discovered_devs_append] need to increase capacity
[ 0.003491] [00016670] libusb: debug [libusb_get_device_descriptor]
[ 0.003499] [00016670] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.003503] [00016670] libusb: debug [parse_endpoint] skipping descriptor 0x30
('<usb1.USBContext object at 0x7f596eb7da90>', '__registerFinalizer', '140022086358784', "<finalize object at 0x7f596e8ad140; for 'USBDevice' at 0x7f596eb7d700>")
('<usb1.USBContext object at 0x7f596eb7da90>', '__unregisterFinalizer', '140022086358784')
[ 0.003584] [00016670] libusb: debug [libusb_get_device_descriptor]
[ 0.003591] [00016670] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.003594] [00016670] libusb: debug [parse_configuration] skipping descriptor 0x9
('<usb1.USBContext object at 0x7f596eb7da90>', '__registerFinalizer', '140022086358832', "<finalize object at 0x7f596e8ad1e0; for 'USBDevice' at 0x7f596eb7d730>")
[ 0.003647] [00016670] libusb: debug [libusb_open] open 1.14
[ 0.003663] [00016670] libusb: debug [usbi_add_event_source] add fd 7 events 4
('<usb1.USBDevice object at 0x7f596eb7d730>', '__registerFinalizer', '140022086359456', "<finalize object at 0x7f596e8ad140; for 'USBDeviceHandle' at 0x7f596eb7d9a0>")
[ 0.003689] [00016670] libusb: debug [libusb_claim_interface] interface 0
[ 0.003736] [00016670] libusb: debug [libusb_alloc_transfer] transfer 0x209f8e8
[ 0.003739] [00016670] libusb: debug [libusb_submit_transfer] transfer 0x209f8e8
[ 0.003743] [00016670] libusb: debug [submit_bulk_transfer] need 1 urbs for new transfer with length 100
[ 0.003757] [00016670] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.003759] [00016670] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.003763] [00016670] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms
[ 0.003776] [00016670] libusb: debug [usbi_wait_for_events] poll() returned 1
[ 0.003779] [00016670] libusb: debug [reap_for_handle] urb type=3 status=0 transferred=100
[ 0.003782] [00016670] libusb: debug [handle_bulk_completion] handling completion status 0 of bulk urb 1/1
[ 0.003784] [00016670] libusb: debug [handle_bulk_completion] all URBs in transfer reaped --> complete!
[ 0.003787] [00016670] libusb: debug [usbi_handle_transfer_completion] transfer 0x209f8e8 has callback 0x7f596e883dc0
[ 0.003789] [00016670] libusb: debug [sync_transfer_cb] actual_length=100
[ 0.003792] [00016670] libusb: debug [libusb_free_transfer] transfer 0x209f8e8
[ 0.003818] [00016670] libusb: debug [libusb_release_interface] interface 0
Number of bytes written: 100
[ 0.003852] [00016670] libusb: debug [libusb_close]
[ 0.003855] [00016670] libusb: debug [usbi_remove_event_source] remove fd 7
('<usb1.USBDevice object at 0x7f596eb7d730>', '__unregisterFinalizer', '140022086359456')
write: True
[ 0.003897] [00016670] libusb: debug [libusb_get_device_list]
[ 0.003902] [00016670] libusb: debug [discovered_devs_append] need to increase capacity
[ 0.003911] [00016670] libusb: debug [libusb_get_device_descriptor]
[ 0.003917] [00016670] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.003920] [00016670] libusb: debug [parse_endpoint] skipping descriptor 0x30
('<usb1.USBContext object at 0x7f596eb7da90>', '__registerFinalizer', '140022086358736', "<finalize object at 0x7f596e8ad240; for 'USBDevice' at 0x7f596eb7d6d0>")
('<usb1.USBContext object at 0x7f596eb7da90>', '__unregisterFinalizer', '140022086358736')
[ 0.003954] [00016670] libusb: debug [libusb_get_device_descriptor]
[ 0.003973] [00016670] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.003976] [00016670] libusb: debug [parse_configuration] skipping descriptor 0x9
('<usb1.USBContext object at 0x7f596eb7da90>', '__registerFinalizer', '140022086358592', "<finalize object at 0x7f596e8ad280; for 'USBDevice' at 0x7f596eb7d640>")
[ 0.004005] [00016670] libusb: debug [libusb_open] open 1.14
[ 0.004015] [00016670] libusb: debug [usbi_add_event_source] add fd 7 events 4
('<usb1.USBDevice object at 0x7f596eb7d640>', '__registerFinalizer', '140022086358784', "<finalize object at 0x7f596e8ad240; for 'USBDeviceHandle' at 0x7f596eb7d700>")
[ 0.004034] [00016670] libusb: debug [libusb_claim_interface] interface 0
[ 0.004075] [00016670] libusb: debug [libusb_alloc_transfer] transfer 0x209d548
[ 0.004079] [00016670] libusb: debug [libusb_submit_transfer] transfer 0x209d548
[ 0.004081] [00016670] libusb: debug [add_to_flying_list] arm timer for timeout in 10ms (first in line)
[ 0.004085] [00016670] libusb: debug [submit_bulk_transfer] need 1 urbs for new transfer with length 1024
[ 0.004091] [00016670] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.004094] [00016670] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.004097] [00016670] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms
[ 0.014156] [00016670] libusb: debug [usbi_wait_for_events] poll() returned 1
[ 0.014185] [00016670] libusb: debug [libusb_cancel_transfer] transfer 0x209d548
[ 0.014308] [00016670] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.014348] [00016670] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.014357] [00016670] libusb: debug [usbi_wait_for_events] poll() 3 fds with timeout in 60000ms
[ 0.014372] [00016670] libusb: debug [usbi_wait_for_events] poll() returned 1
[ 0.014387] [00016670] libusb: debug [reap_for_handle] urb type=3 status=-2 transferred=0
[ 0.014399] [00016670] libusb: debug [handle_bulk_completion] handling completion status -2 of bulk urb 1/1
[ 0.014408] [00016670] libusb: debug [handle_bulk_completion] abnormal reap: urb status -2
[ 0.014418] [00016670] libusb: debug [handle_bulk_completion] abnormal reap: last URB handled, reporting
[ 0.014426] [00016670] libusb: debug [usbi_handle_transfer_cancellation] detected timeout cancellation
[ 0.014436] [00016670] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.014446] [00016670] libusb: debug [usbi_handle_transfer_completion] transfer 0x209d548 has callback 0x7f596e883dc0
[ 0.014456] [00016670] libusb: debug [sync_transfer_cb] actual_length=0
[ 0.014468] [00016670] libusb: debug [libusb_free_transfer] transfer 0x209d548
[ 0.014557] [00016670] libusb: debug [libusb_release_interface] interface 0
[ 0.014627] [00016670] libusb: debug [libusb_close]
[ 0.014647] [00016670] libusb: debug [usbi_remove_event_source] remove fd 7
('<usb1.USBDevice object at 0x7f596eb7d640>', '__unregisterFinalizer', '140022086358784')
read: bytearray(b'')
Closing USB
('<usb1.USBContext object at 0x7f596eb7da90>', '__unregisterFinalizer', '140022086358832')
('<usb1.USBContext object at 0x7f596eb7da90>', '__unregisterFinalizer', '140022086358592')
[ 0.014933] [00016670] libusb: debug [libusb_exit]
[ 0.014947] [00016670] libusb: debug [libusb_exit] destroying default context
[ 0.014961] [00016670] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.014974] [00016670] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.014993] [00016670] libusb: debug [usbi_wait_for_events] poll() 2 fds with timeout in 0ms
[ 0.015009] [00016670] libusb: debug [usbi_wait_for_events] poll() returned 0
[ 0.015022] [00016670] libusb: debug [libusb_unref_device] destroy device 2.1
[ 0.015036] [00016670] libusb: debug [libusb_unref_device] destroy device 1.14
[ 0.015050] [00016670] libusb: debug [libusb_unref_device] destroy device 1.13
[ 0.015063] [00016670] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.015075] [00016670] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.015089] [00016670] libusb: debug [libusb_unref_device] destroy device 1.5
[ 0.015102] [00016670] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.015116] [00016670] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.015129] [00016670] libusb: debug [libusb_unref_device] destroy device 4.1
[ 0.015142] [00016670] libusb: debug [libusb_unref_device] destroy device 3.1
[ 0.015156] [00016670] libusb: debug [usbi_remove_event_source] remove fd 6
[ 0.015183] [00016670] libusb: debug [usbi_remove_event_source] remove fd 5
[ 0.015261] [00016671] libusb: debug [linux_udev_event_thread_main] udev event thread exiting
Close handle successfully
Calling closing method to delete self
Closing USB
Close handle successfully
win10 output (LIBUSB_DEBUG=4)
> $Env:LIBUSB_DEBUG=4; .\python.exe C:\Users\vincent\git\python-libusb1\examples\readwrite.py
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.001296] [000003b4] libusb: debug [libusb_init] created default context
[ 0.001891] [000003b4] libusb: debug [libusb_init] libusb v1.0.24.11584
[ 0.002013] [000003b4] libusb: debug [get_windows_version] Windows 10 64-bit
[ 0.002280] [000003b4] libusb: debug [htab_create] using 1021 entries hash table
[ 0.003686] [000003b4] libusb: info [winusbx_init] WinUSB DLL available (with isoch support)
[ 0.004101] [000003b4] libusb: info [winusbx_init] libusbK DLL is not available
[ 0.005285] [000003b4] libusb: info [windows_init] UsbDk backend is not available
[ 0.005556] [000003b4] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000120 events 0
[ 0.005858] [000003b4] libusb: debug [usbi_io_init] using timer for timeouts
[ 0.006328] [000003b4] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000238 events 0
[ 0.006364] [0000117c] libusb: debug [windows_iocp_thread] I/O completion thread started
[ 0.006930] [000003b4] libusb: debug [libusb_get_device_list]
[ 0.011698] [000003b4] libusb: debug [winusb_get_device_list] allocating new device for session [2A]
[ 0.012162] [000003b4] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.012323] [000003b4] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.012488] [000003b4] libusb: debug [winusb_get_device_list] allocating new device for session [18]
[ 0.012966] [000003b4] libusb: debug [get_api_type] driver(s): HidUsb
[ 0.013115] [000003b4] libusb: debug [get_api_type] matched driver name against HID API
[ 0.013267] [000003b4] libusb: debug [winusb_get_device_list] allocating new device for session [1F]
[ 0.013803] [000003b4] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_1E31&SUBSYS_00000000&REV_00\3&267A616A&0&60' bus number 1
[ 0.014295] [000003b4] libusb: debug [winusb_get_device_list] extra GUID: {6567F511-0B21-433B-9D69-533059C48C7E}
[ 0.014359] [000003b4] libusb: debug [winusb_get_device_list] found existing device for session [18]
[ 0.014792] [000003b4] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.014975] [000003b4] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 35 bytes)
[ 0.015285] [000003b4] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 2): 'USB\VID_1D6B&PID_0104\5&12C8F4C0&0&2'
[ 0.015750] [000003b4] libusb: debug [winusb_get_device_list] found existing device for session [1F]
[ 0.015914] [000003b4] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.016103] [000003b4] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 34 bytes)
[ 0.016393] [000003b4] libusb: debug [init_device] (bus: 1, addr: 1, depth: 1, port: 1): 'USB\VID_80EE&PID_0021\5&12C8F4C0&0&1'
[ 0.016789] [000003b4] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\4&24054718&0&0' reports 14 ports
[ 0.019604] [000003b4] libusb: debug [init_device] (bus: 1, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\4&24054718&0&0'
[ 0.021287] [000003b4] libusb: debug [winusb_get_device_list] setting HID interface for [1F]:
[ 0.021383] [000003b4] libusb: debug [set_hid_interface] interface[0] = \\?\HID#VID_80EE&PID_0021#6&C0114FE&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.022312] [000003b4] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.022519] [000003b4] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.023136] [000003b4] libusb: debug [libusb_get_device_descriptor]
[ 0.023235] [000003b4] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.023559] [000003b4] libusb: debug [parse_configuration] skipping descriptor 0x9
[ 0.023720] [000003b4] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.024032] [000003b4] libusb: debug [libusb_open] open 1.2
[ 0.024371] [000003b4] libusb: debug [libusb_claim_interface] interface 0
[ 0.024682] [000003b4] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.024853] [000003b4] libusb: debug [parse_configuration] skipping descriptor 0x9
[ 0.025123] [000003b4] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.025421] [000003b4] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 01 to interface 0
[ 0.025906] [000003b4] libusb: debug [libusb_alloc_transfer] transfer 000002C9D2C67518
[ 0.026041] [000003b4] libusb: debug [libusb_submit_transfer] transfer 000002C9D2C67518
[ 0.026313] [000003b4] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 01 with interface 0
[ 0.026619] [000003b4] libusb: debug [winusbx_submit_bulk_transfer] writing 100 bytes
[ 0.027105] [000003b4] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.027248] [0000117c] libusb: debug [windows_iocp_thread] transfer 000002C9D2C67518 completed, length 100
[ 0.027434] [000003b4] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.027994] [000003b4] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.028256] [000003b4] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.028557] [000003b4] libusb: debug [handle_event_trigger] event triggered
[ 0.028892] [000003b4] libusb: debug [windows_handle_transfer_completion] handling transfer 000002C9D2C67518 completion with errcode 0, length 100
[ 0.029193] [000003b4] libusb: debug [usbi_handle_transfer_completion] transfer 000002C9D2C67518 has callback 00007FFED7029390
[ 0.029497] [000003b4] libusb: debug [sync_transfer_cb] actual_length=100
[ 0.029811] [000003b4] libusb: debug [libusb_free_transfer] transfer 000002C9D2C67518
[ 0.030109] [000003b4] libusb: debug [libusb_release_interface] interface 0
Number of bytes written: 100
[ 0.030740] [000003b4] libusb: debug [libusb_close]
write: True
[ 0.031397] [000003b4] libusb: debug [libusb_get_device_list]
[ 0.036796] [000003b4] libusb: debug [winusb_get_device_list] found existing device for session [2A]
[ 0.037263] [000003b4] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.037473] [000003b4] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.037685] [000003b4] libusb: debug [winusb_get_device_list] found existing device for session [18]
[ 0.037976] [000003b4] libusb: debug [get_api_type] driver(s): HidUsb
[ 0.038046] [000003b4] libusb: debug [get_api_type] matched driver name against HID API
[ 0.038320] [000003b4] libusb: debug [winusb_get_device_list] allocating new device for session [1F]
[ 0.038906] [000003b4] libusb: debug [winusb_get_device_list] extra GUID: {6567F511-0B21-433B-9D69-533059C48C7E}
[ 0.039082] [000003b4] libusb: debug [winusb_get_device_list] found existing device for session [18]
[ 0.039581] [000003b4] libusb: debug [winusb_get_device_list] found existing device for session [1F]
[ 0.039786] [000003b4] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.040011] [000003b4] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 34 bytes)
[ 0.040351] [000003b4] libusb: debug [init_device] (bus: 1, addr: 1, depth: 1, port: 1): 'USB\VID_80EE&PID_0021\5&12C8F4C0&0&1'
[ 0.040923] [000003b4] libusb: debug [winusb_get_device_list] setting HID interface for [1F]:
[ 0.040997] [000003b4] libusb: debug [set_hid_interface] interface[0] = \\?\HID#VID_80EE&PID_0021#6&C0114FE&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.041492] [000003b4] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.041708] [000003b4] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.042225] [000003b4] libusb: debug [libusb_get_device_descriptor]
[ 0.042307] [000003b4] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.042655] [000003b4] libusb: debug [parse_configuration] skipping descriptor 0x9
[ 0.042817] [000003b4] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.043056] [000003b4] libusb: debug [libusb_open] open 1.2
[ 0.043487] [000003b4] libusb: debug [libusb_claim_interface] interface 0
[ 0.043830] [000003b4] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.043984] [000003b4] libusb: debug [parse_configuration] skipping descriptor 0x9
[ 0.044298] [000003b4] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.044557] [000003b4] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 01 to interface 0
[ 0.045072] [000003b4] libusb: debug [libusb_alloc_transfer] transfer 000002C9D2C67518
[ 0.045271] [000003b4] libusb: debug [libusb_submit_transfer] transfer 000002C9D2C67518
[ 0.045620] [000003b4] libusb: debug [add_to_flying_list] arm timer for timeout in 10ms (first in line)
[ 0.045910] [000003b4] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 81 with interface 0
[ 0.046235] [000003b4] libusb: debug [winusbx_submit_bulk_transfer] reading 1024 bytes
[ 0.046667] [000003b4] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.046828] [000003b4] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.058986] [000003b4] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 1
[ 0.059751] [000003b4] libusb: debug [libusb_cancel_transfer] transfer 000002C9D2C67518
[ 0.060286] [000003b4] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.060659] [0000117c] libusb: debug [windows_iocp_thread] transfer 000002C9D2C67518 completed, length 0
[ 0.060789] [000003b4] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.061069] [000003b4] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.061124] [000003b4] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.061403] [000003b4] libusb: debug [handle_event_trigger] event triggered
[ 0.061705] [000003b4] libusb: debug [windows_handle_transfer_completion] handling transfer 000002C9D2C67518 completion with errcode 995, length 0
[ 0.061996] [000003b4] libusb: debug [windows_handle_transfer_completion] detected operation aborted
[ 0.062258] [000003b4] libusb: debug [usbi_handle_transfer_cancellation] detected timeout cancellation
[ 0.062534] [000003b4] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.062837] [000003b4] libusb: debug [usbi_handle_transfer_completion] transfer 000002C9D2C67518 has callback 00007FFED7029390
[ 0.063113] [000003b4] libusb: debug [sync_transfer_cb] actual_length=0
[ 0.063370] [000003b4] libusb: debug [libusb_free_transfer] transfer 000002C9D2C67518
[ 0.063755] [000003b4] libusb: debug [libusb_release_interface] interface 0
[ 0.064057] [000003b4] libusb: debug [libusb_close]
read: bytearray(b'')
Closing USB
[ 0.064870] [000003b4] libusb: error [libusb_set_pollfd_notifiers] external polling of libusb's internal event sources is not yet supported on Windows
[ 0.065282] [000003b4] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.065452] [000003b4] libusb: debug [libusb_exit]
[ 0.065708] [000003b4] libusb: debug [libusb_exit] destroying default context
[ 0.065967] [000003b4] libusb: warning [libusb_exit] some libusb_devices were leaked
[ 0.066258] [000003b4] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000238
[ 0.066573] [000003b4] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000120
[ 0.066951] [0000117c] libusb: debug [windows_iocp_thread] I/O completion thread exiting
Close handle successfully
Calling closing method to delete self
Closing USB
Close handle successfully
EDIT: the linux output includes non-committed debug prints in finalizer {un,}register functions.
from python-libusb1.
Ah, I did not finish explaining my train of thought: As you do not create any async transfer and do not call handle_events
, this means that the infinite loop you are getting comes from the bulkWrite
itself. And it should not be affected by the changes I did...
So while I trust that your device is working, I was suspecting that for whatever reason (my previous bug having put it and/or windows in a weird state ?) it was not responding anymore. Maybe unplug/replug could have been enough (more if it was windows that was confused).
from python-libusb1.
libusb: error [libusb_set_pollfd_notifiers] external polling of libusb's internal event sources is not yet supported on Windows
Nice catch, I missed this in all the debug output.
This should be fixed by 976866d (checked with my win10 vm, the error message does not appear anymore).
from python-libusb1.
Hello, thanks for the very detailed report.
At a glance I do not see anything wrong with the code structure.
The only less-usual thing I see is the creation of a second context in is_connected
, but this is supposed to work so it is definitely not wrong. It just maybe less commonly exercised than single-context-at-a-time, so bugs could be hiding there that others would not have caught, so in the spirit of trying to eliminate all possible causes I prefer to mention it.
On to the error: this looks like a double-free, somehow, which points at a double-close
(possibly close
-then-__del__
) of the USBDevice
. This method has code supposed to prevent this from happening, and barring any race-condition this should work. This minimal test-case being single-threaded there should be no race here, so there must be something else I am not seeing.
Could you add the following line as first line of USBDevice.close
(it should become line 1781), and re-run the test ?
print('<USBDevice %x>.close called, self.device_p=%r (%s)' % (id(self), self.device_p, bool(self.device_p))
from python-libusb1.
What is really strange is that when I call the close
method in __del__
it works, but when I call it within the main I get the exception. BTW I added what you said.
True
write: True
read: bytearray(b'AAAAAAAAAA')
<USBDevice 1e58feff070>.close called, self.device_p=<usb1.libusb1.LP_libusb_device object at 0x000001E591DF3440> (True)
<USBDevice 1e58feff070>.close called, self.device_p=None (False)
<USBDevice 1e58fefad00>.close called, self.device_p=<usb1.libusb1.LP_libusb_device object at 0x000001E591DF37C0> (True)
<USBDevice 1e58fefa460>.close called, self.device_p=<usb1.libusb1.LP_libusb_device object at 0x000001E591DF3B40> (True)
Exception ignored in: <function USBDevice.__del__ at 0x000001E591DAA9D0>
Traceback (most recent call last):
File "C:\Users\ABC\AppData\Roaming\Python\Python39\site-packages\usb1\__init__.py", line 1778, in __del__
self.close()
File "C:\Users\ABC\AppData\Roaming\Python\Python39\site-packages\usb1\__init__.py", line 1791, in close
self.__libusb_unref_device(self.device_p)
OSError: exception: access violation writing 0x0000000000000024
from python-libusb1.
What is really strange is that when I call the
close
method in__del__
it works, but when I call it within the main I get the exception
Interpreter shutdown is doing very unusual things when trying to call every destructor.
Like replacing all module globals with None
, and I believe also breaking cycles.
This is why I went with context-manager-based instance lifetime control: this provides unambiguous teardown ordering, as it happens before reaching interpreter shutdown but instead whywhile control is going up the stack.
BTW I added what you said.
Thanks, and these outputs all look fine to me: there is no obvious reason why a null pointer appears here.
from python-libusb1.
Actually I don't have a problem with that but cause my unit tests to fail.
import unittest
from core import USB
class TestUSB(unittest.TestCase):
"""Test USB Functions"""
VENDOR_ID = 0x04b4
PRODUCT_ID = 0x00f0
ENDPOINT_IN = 0x81
ENDPOINT_OUT = 0x01
MSG = 100 * bytearray(b"A")
def setUp(self) -> None:
self.usb = USB(self.PRODUCT_ID, self.VENDOR_ID,
self.ENDPOINT_IN, self.ENDPOINT_OUT)
self.assertTrue(self.usb.open())
def tearDown(self) -> None:
pass
def test_read_write(self):
self.assertTrue(self.usb.is_connected())
self.assertTrue(self.usb.write(self.MSG))
self.assertTrue(self.MSG == self.usb.read())
from python-libusb1.
I'm sorry but I do not understand what you mean in your latest comment.
from python-libusb1.
Suppose I don't call self.close()
explicitly, it won't give me the exception, and the program closes normally. But in my unit test, it throws the exception even without calling self.close()
and that is strange for me.
from python-libusb1.
If I stick to my gut feeling that this is an interpreter-shutdown-specific issue, one thing I can think of is that maybe the presence/absence of __del__
methods on the involved classes can make a difference. Python's garbage collector behaves differently when a class has a __del__
method.
When I wrote the first few version of python-libusb1 I thought I would be able to get away with freeing memory in __del__
methods, so I added them in multiple classes. It is only much later that I realized there is no way around using context management for reliable memory de-allocation. So I added __enter__
/__exit__
, close
for any code which does not naturally lend itself to the context manager approach, plus some data structures to locate the managed instances and close
them. But I had to maintain backward compatibility, so __del__
methods still remain today, with their sometimes weird gc effects.
So I am not too surprised that relying on __del__
to close everything during interpreter shutdown causes some issue. What I still do not understand here is why when you added an explicit close
call you were getting errors - and the null-pointer was never visible in the logs I made you add. Maybe you can increase the amount of debug prints, like in every __del__
method to track the order in which they get called ? Also adding a print before and after the explicit close
call, to see if the issue happens while close is still running, or if it is after it has returned, hence during interpreter shutdown. Including repr(self)
or id(self)
in these prints would be good.
from python-libusb1.
Interestingly I do not have any issues under my Mac Mini M1 running macOS Big Sur 11.5 ARM64 version with the test code mentioned in the first post. Recently I got the Cypress FX3 board and it is a wonderful board to play with USB under different OS (Windows, macOS and Linux for me).
pyusb/pyusb_test/usb1 via 🐍 v3.9.6 (py396venv) ❯ python3 cyusb_fx3_bulkloop.py
True
write: True
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
from python-libusb1.
But I can reproduce the issue under Windows with the official Python 3.9.6 x64 version.
(py39venv) C:\work\libusb\python_usb [master ≡ +7 ~0 -0 !]> python .\cyusb_fx3_loopback_python_libusb1.py
True
write: True
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
Exception ignored in: <function USBDevice.__del__ at 0x0000015C8C6DC0D0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1778, in __del__
self.close()
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1790, in close
self.__libusb_unref_device(self.device_p)
OSError: exception: access violation writing 0x0000000000000024
from python-libusb1.
And if I use MSYS2 MinGW64 Python, it actually segfaults.
MINGW64 /c/work/libusb/python_usb
$ python cyusb_fx3_loopback_python_libusb1.py
True
write: True
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
Segmentation fault
from python-libusb1.
With Windows Python, the full debug log (LIBUSB_DEBUG=4). Not so sure if this helps.
click to expand
(py39venv) C:\work\libusb\python_usb [master ≡ +7 ~0 -0 !]> python .\cyusb_fx3_loopback_python_libusb1.py
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000324] [00003230] libusb: debug [libusb_init] created default context
[ 0.000469] [00003230] libusb: debug [libusb_init] libusb v1.0.24.11584
[ 0.000770] [00003230] libusb: debug [get_windows_version] Windows 10 64-bit
[ 0.000919] [00003230] libusb: debug [htab_create] using 1021 entries hash table
[ 0.003397] [00003230] libusb: info [winusbx_init] WinUSB DLL available (with isoch support)
[ 0.004337] [00003230] libusb: debug [winusbx_init] libusbK DLL found, version: 3.0.8.0
[ 0.009659] [00003230] libusb: debug [windows_init] UsbDk backend is available
[ 0.009962] [00003230] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000220 events 0
[ 0.010150] [00003230] libusb: debug [usbi_io_init] using timer for timeouts
[ 0.010290] [00003230] libusb: debug [usbi_add_event_source] add HANDLE 00000000000002A8 events 0
[ 0.010498] [00003230] libusb: debug [libusb_get_device_list]
[ 0.011023] [00006578] libusb: debug [windows_iocp_thread] I/O completion thread started
[ 0.029920] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [85]
[ 0.030179] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [86]
[ 0.030462] [00003230] libusb: debug [get_api_type] driver(s): BTHUSB
[ 0.030582] [00003230] libusb: debug [get_api_type] lower filter driver(s): ibtusb
[ 0.030663] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [10]
[ 0.031119] [00003230] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.031219] [00003230] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.031292] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [65]
[ 0.031465] [00003230] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.031565] [00003230] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.031642] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [66]
[ 0.031811] [00003230] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.031911] [00003230] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.031985] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [67]
[ 0.032260] [00003230] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_A36D&SUBSYS_091A1028&REV_10\3&11583659&0&A0' bus number 1
[ 0.032398] [00003230] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_15DB&SUBSYS_091A1028&REV_02\71D9F51854B3020000' bus number 2
[ 0.033623] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [10]
[ 0.033789] [00003230] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.033875] [00003230] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 200 bytes)
[ 0.033991] [00003230] libusb: debug [init_device] (bus: 1, addr: 3, depth: 1, port: 14): 'USB\VID_8087&PID_0AAA\5&E9F3E45&0&14'
[ 0.034477] [00003230] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\4&36020D6F&0&0' reports 26 ports
[ 0.034637] [00003230] libusb: debug [init_device] (bus: 1, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\4&36020D6F&0&0'
[ 0.034803] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [67]
[ 0.034940] [00003230] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.035051] [00003230] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 269 bytes)
[ 0.035159] [00003230] libusb: debug [init_device] (bus: 1, addr: 4, depth: 1, port: 10): 'USB\VID_0A5C&PID_5842\0123456789ABCD'
[ 0.035413] [00003230] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\7&2452366F&0&0' reports 4 ports
[ 0.035508] [00003230] libusb: debug [init_device] (bus: 2, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\7&2452366F&0&0'
[ 0.035756] [00003230] libusb: debug [winusb_get_device_list] extra GUID: {BE04C453-E28B-7E96-28B5-5CB14483D2EF}
[ 0.035814] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [66]
[ 0.035903] [00003230] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.035959] [00003230] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 44 bytes)
[ 0.036042] [00003230] libusb: debug [init_device] (bus: 1, addr: 7, depth: 1, port: 17): 'USB\VID_04B4&PID_00F0\5&E9F3E45&0&17'
[ 0.036403] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [65]
[ 0.036490] [00003230] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.036548] [00003230] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 1112 bytes)
[ 0.036625] [00003230] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 11): 'USB\VID_0BDA&PID_58FD\200901010001'
[ 0.036977] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL01\7&290AACAE&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.037084] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL01\5&99B72D3&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.037213] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL03\5&379854AA&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.037388] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL01\3&36A7043C&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.037500] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL02\7&290AACAE&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.037599] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL02\3&36A7043C&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.037700] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL02\5&99B72D3&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.037806] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL02\5&379854AA&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.037911] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL03\5&99B72D3&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.038014] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL04\5&99B72D3&0&0003' (non USB HID, newly connected, etc.) - ignoring
[ 0.038116] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL05\5&99B72D3&0&0004' (non USB HID, newly connected, etc.) - ignoring
[ 0.038222] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL01\5&379854AA&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.038937] [00003230] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.039017] [00003230] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.039502] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.039563] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.039651] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.039703] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.039748] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.039835] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.039885] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.039961] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.040012] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.040055] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.040129] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.040179] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.040226] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.040269] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.040338] [00003230] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.040385] [00003230] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.040430] [00003230] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.040474] [00003230] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.040560] [00003230] libusb: debug [libusb_unref_device] destroy device 1.7
[ 0.040605] [00003230] libusb: debug [libusb_unref_device] destroy device 1.0
[ 0.040659] [00003230] libusb: debug [libusb_exit]
[ 0.040703] [00003230] libusb: debug [libusb_exit] destroying default context
[ 0.040745] [00003230] libusb: debug [usbi_remove_event_source] remove HANDLE 00000000000002A8
[ 0.040793] [00003230] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000220
[ 0.040993] [00006578] libusb: debug [windows_iocp_thread] I/O completion thread exiting
True
[ 0.042604] [00003230] libusb: debug [libusb_init] created default context
[ 0.042653] [00003230] libusb: debug [libusb_init] libusb v1.0.24.11584
[ 0.042818] [00003230] libusb: debug [get_windows_version] Windows 10 64-bit
[ 0.042865] [00003230] libusb: debug [htab_create] using 1021 entries hash table
[ 0.045098] [00003230] libusb: info [winusbx_init] WinUSB DLL available (with isoch support)
[ 0.045947] [00003230] libusb: debug [winusbx_init] libusbK DLL found, version: 3.0.8.0
[ 0.050823] [00003230] libusb: debug [windows_init] UsbDk backend is available
[ 0.051131] [00003230] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000220 events 0
[ 0.051247] [00003230] libusb: debug [usbi_io_init] using timer for timeouts
[ 0.051306] [00003230] libusb: debug [usbi_add_event_source] add HANDLE 00000000000002A8 events 0
[ 0.051318] [000067e4] libusb: debug [windows_iocp_thread] I/O completion thread started
[ 0.051437] [00003230] libusb: debug [libusb_get_device_list]
[ 0.070022] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [85]
[ 0.070368] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [86]
[ 0.070689] [00003230] libusb: debug [get_api_type] driver(s): BTHUSB
[ 0.070838] [00003230] libusb: debug [get_api_type] lower filter driver(s): ibtusb
[ 0.070945] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [10]
[ 0.071393] [00003230] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.071531] [00003230] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.071633] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [65]
[ 0.071809] [00003230] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.071937] [00003230] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.072039] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [66]
[ 0.072213] [00003230] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.072338] [00003230] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.072436] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [67]
[ 0.072709] [00003230] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_A36D&SUBSYS_091A1028&REV_10\3&11583659&0&A0' bus number 1
[ 0.072868] [00003230] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_15DB&SUBSYS_091A1028&REV_02\71D9F51854B3020000' bus number 2
[ 0.074121] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [10]
[ 0.074283] [00003230] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.074394] [00003230] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 200 bytes)
[ 0.074543] [00003230] libusb: debug [init_device] (bus: 1, addr: 3, depth: 1, port: 14): 'USB\VID_8087&PID_0AAA\5&E9F3E45&0&14'
[ 0.075051] [00003230] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\4&36020D6F&0&0' reports 26 ports
[ 0.075307] [00003230] libusb: debug [init_device] (bus: 1, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\4&36020D6F&0&0'
[ 0.075555] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [67]
[ 0.075708] [00003230] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.075819] [00003230] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 269 bytes)
[ 0.076008] [00003230] libusb: debug [init_device] (bus: 1, addr: 4, depth: 1, port: 10): 'USB\VID_0A5C&PID_5842\0123456789ABCD'
[ 0.076294] [00003230] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\7&2452366F&0&0' reports 4 ports
[ 0.076412] [00003230] libusb: debug [init_device] (bus: 2, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\7&2452366F&0&0'
[ 0.076681] [00003230] libusb: debug [winusb_get_device_list] extra GUID: {BE04C453-E28B-7E96-28B5-5CB14483D2EF}
[ 0.076766] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [66]
[ 0.076879] [00003230] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.076963] [00003230] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 44 bytes)
[ 0.077070] [00003230] libusb: debug [init_device] (bus: 1, addr: 7, depth: 1, port: 17): 'USB\VID_04B4&PID_00F0\5&E9F3E45&0&17'
[ 0.077410] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [65]
[ 0.077520] [00003230] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.077606] [00003230] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 1112 bytes)
[ 0.077714] [00003230] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 11): 'USB\VID_0BDA&PID_58FD\200901010001'
[ 0.078093] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL01\7&290AACAE&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.078230] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL01\5&99B72D3&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.078384] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL03\5&379854AA&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.078510] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL01\3&36A7043C&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.078647] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL02\7&290AACAE&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.078799] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL02\3&36A7043C&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.078944] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL02\5&99B72D3&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.079050] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL02\5&379854AA&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.079152] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL03\5&99B72D3&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.079253] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL04\5&99B72D3&0&0003' (non USB HID, newly connected, etc.) - ignoring
[ 0.079356] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL05\5&99B72D3&0&0004' (non USB HID, newly connected, etc.) - ignoring
[ 0.079462] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL01\5&379854AA&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.080193] [00003230] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.080275] [00003230] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.080773] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.080833] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.080914] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.080966] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.081012] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.081102] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.081158] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.081237] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.081287] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.081330] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.081401] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.081452] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.081496] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.081540] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.081608] [00003230] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.081656] [00003230] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.081701] [00003230] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.081744] [00003230] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.081819] [00003230] libusb: debug [libusb_open] open 1.7
[ 0.081912] [00003230] libusb: debug [libusb_claim_interface] interface 0
[ 0.082059] [00003230] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.082109] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.082155] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.082199] [00003230] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 01 to interface 0
[ 0.082246] [00003230] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.082410] [00003230] libusb: debug [libusb_alloc_transfer] transfer 0000027B52B3A1C8
[ 0.082461] [00003230] libusb: debug [libusb_submit_transfer] transfer 0000027B52B3A1C8
[ 0.082506] [00003230] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 01 with interface 0
[ 0.082550] [00003230] libusb: debug [winusbx_submit_bulk_transfer] writing 100 bytes
[ 0.082627] [00003230] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.082674] [00003230] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.082722] [00003230] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.082684] [000067e4] libusb: debug [windows_iocp_thread] transfer 0000027B52B3A1C8 completed, length 100
[ 0.082889] [00003230] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.082934] [00003230] libusb: debug [handle_event_trigger] event triggered
[ 0.082977] [00003230] libusb: debug [windows_handle_transfer_completion] handling transfer 0000027B52B3A1C8 completion with errcode 0, length 100
[ 0.083045] [00003230] libusb: debug [usbi_handle_transfer_completion] transfer 0000027B52B3A1C8 has callback 00007FFAE6689390
[ 0.083114] [00003230] libusb: debug [sync_transfer_cb] actual_length=100
[ 0.083158] [00003230] libusb: debug [libusb_free_transfer] transfer 0000027B52B3A1C8
[ 0.083216] [00003230] libusb: debug [libusb_release_interface] interface 0
[ 0.083272] [00003230] libusb: debug [libusb_close]
write: True
[ 0.083461] [00003230] libusb: debug [libusb_get_device_list]
[ 0.098864] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [85]
[ 0.099088] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [86]
[ 0.099364] [00003230] libusb: debug [get_api_type] driver(s): BTHUSB
[ 0.099505] [00003230] libusb: debug [get_api_type] lower filter driver(s): ibtusb
[ 0.099608] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [10]
[ 0.100028] [00003230] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.100157] [00003230] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.100257] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [65]
[ 0.100427] [00003230] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.100556] [00003230] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.100655] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [66]
[ 0.100823] [00003230] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.100949] [00003230] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.101056] [00003230] libusb: debug [winusb_get_device_list] allocating new device for session [67]
[ 0.101411] [00003230] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_15DB&SUBSYS_091A1028&REV_02\71D9F51854B3020000' bus number 2
[ 0.102847] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [10]
[ 0.103112] [00003230] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.103235] [00003230] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 200 bytes)
[ 0.103389] [00003230] libusb: debug [init_device] (bus: 1, addr: 3, depth: 1, port: 14): 'USB\VID_8087&PID_0AAA\5&E9F3E45&0&14'
[ 0.103991] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [67]
[ 0.104136] [00003230] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.104254] [00003230] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 269 bytes)
[ 0.104406] [00003230] libusb: debug [init_device] (bus: 1, addr: 4, depth: 1, port: 10): 'USB\VID_0A5C&PID_5842\0123456789ABCD'
[ 0.104692] [00003230] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\7&2452366F&0&0' reports 4 ports
[ 0.104796] [00003230] libusb: debug [init_device] (bus: 2, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\7&2452366F&0&0'
[ 0.105035] [00003230] libusb: debug [winusb_get_device_list] extra GUID: {BE04C453-E28B-7E96-28B5-5CB14483D2EF}
[ 0.105122] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [66]
[ 0.105470] [00003230] libusb: debug [winusb_get_device_list] found existing device for session [65]
[ 0.105580] [00003230] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.105665] [00003230] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 1112 bytes)
[ 0.105770] [00003230] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 11): 'USB\VID_0BDA&PID_58FD\200901010001'
[ 0.106119] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL01\7&290AACAE&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.106255] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL01\5&99B72D3&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.106408] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL03\5&379854AA&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.106533] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL01\3&36A7043C&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.106667] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL02\7&290AACAE&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.106795] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL02\3&36A7043C&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.106926] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL02\5&99B72D3&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.107066] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL02\5&379854AA&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.107322] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL03\5&99B72D3&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.107507] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL04\5&99B72D3&0&0003' (non USB HID, newly connected, etc.) - ignoring
[ 0.107682] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL05\5&99B72D3&0&0004' (non USB HID, newly connected, etc.) - ignoring
[ 0.107879] [00003230] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL01\5&379854AA&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.108673] [00003230] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.108830] [00003230] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.109392] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.109517] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.109695] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.109817] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.109928] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.110106] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.110228] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.110385] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.110520] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.110630] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.110785] [00003230] libusb: debug [libusb_get_device_descriptor]
[ 0.110913] [00003230] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.111015] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.111107] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.111217] [00003230] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.111306] [00003230] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.111410] [00003230] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.111464] [00003230] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.111545] [00003230] libusb: debug [libusb_open] open 1.7
[ 0.111645] [00003230] libusb: debug [libusb_claim_interface] interface 0
[ 0.111757] [00003230] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.111807] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.111853] [00003230] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.111897] [00003230] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 01 to interface 0
[ 0.111946] [00003230] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.112107] [00003230] libusb: debug [libusb_alloc_transfer] transfer 0000027B5457D2B8
[ 0.112156] [00003230] libusb: debug [libusb_submit_transfer] transfer 0000027B5457D2B8
[ 0.112202] [00003230] libusb: debug [add_to_flying_list] arm timer for timeout in 10ms (first in line)
[ 0.112272] [00003230] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 81 with interface 0
[ 0.112320] [00003230] libusb: debug [winusbx_submit_bulk_transfer] reading 1024 bytes
[ 0.112400] [00003230] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.112448] [00003230] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.112463] [000067e4] libusb: debug [windows_iocp_thread] transfer 0000027B5457D2B8 completed, length 100
[ 0.112662] [00003230] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.112708] [00003230] libusb: debug [handle_event_trigger] event triggered
[ 0.112753] [00003230] libusb: debug [windows_handle_transfer_completion] handling transfer 0000027B5457D2B8 completion with errcode 0, length 100
[ 0.112824] [00003230] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.112872] [00003230] libusb: debug [usbi_handle_transfer_completion] transfer 0000027B5457D2B8 has callback 00007FFAE6689390
[ 0.112943] [00003230] libusb: debug [sync_transfer_cb] actual_length=100
[ 0.112990] [00003230] libusb: debug [libusb_free_transfer] transfer 0000027B5457D2B8
[ 0.113062] [00003230] libusb: debug [libusb_alloc_transfer] transfer 0000027B5457D2B8
[ 0.113110] [00003230] libusb: debug [libusb_submit_transfer] transfer 0000027B5457D2B8
[ 0.113156] [00003230] libusb: debug [add_to_flying_list] arm timer for timeout in 10ms (first in line)
[ 0.113203] [00003230] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 81 with interface 0
[ 0.113250] [00003230] libusb: debug [winusbx_submit_bulk_transfer] reading 1024 bytes
[ 0.113312] [00003230] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.113359] [00003230] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.123041] [00003230] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 1
[ 0.123170] [00003230] libusb: debug [libusb_cancel_transfer] transfer 0000027B5457D2B8
[ 0.123322] [00003230] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.123468] [00003230] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.123612] [00003230] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.123396] [000067e4] libusb: debug [windows_iocp_thread] transfer 0000027B5457D2B8 completed, length 0
[ 0.124000] [00003230] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.124135] [00003230] libusb: debug [handle_event_trigger] event triggered
[ 0.124273] [00003230] libusb: debug [windows_handle_transfer_completion] handling transfer 0000027B5457D2B8 completion with errcode 995, length 0
[ 0.124439] [00003230] libusb: debug [windows_handle_transfer_completion] detected operation aborted
[ 0.124574] [00003230] libusb: debug [usbi_handle_transfer_cancellation] detected timeout cancellation
[ 0.124709] [00003230] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.124849] [00003230] libusb: debug [usbi_handle_transfer_completion] transfer 0000027B5457D2B8 has callback 00007FFAE6689390
[ 0.125013] [00003230] libusb: debug [sync_transfer_cb] actual_length=0
[ 0.125116] [00003230] libusb: debug [libusb_free_transfer] transfer 0000027B5457D2B8
[ 0.125266] [00003230] libusb: debug [libusb_release_interface] interface 0
[ 0.125381] [00003230] libusb: debug [libusb_close]
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
[ 0.125721] [00003230] libusb: debug [libusb_exit]
[ 0.125819] [00003230] libusb: debug [libusb_exit] destroying default context
[ 0.125896] [00003230] libusb: warning [libusb_exit] some libusb_devices were leaked
[ 0.125941] [00003230] libusb: debug [usbi_remove_event_source] remove HANDLE 00000000000002A8
[ 0.125990] [00003230] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000220
[ 0.126248] [000067e4] libusb: debug [windows_iocp_thread] I/O completion thread exiting
[ 0.130114] [00003230] libusb: debug [libusb_unref_device] destroy device 1.7
Exception ignored in: <function USBDevice.__del__ at 0x0000027B5487C0D0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1778, in __del__
self.close()
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1790, in close
self.__libusb_unref_device(self.device_p)
OSError: exception: access violation writing 0x0000000000000024
from python-libusb1.
The following debug log seems to be a bit suspicious. Is it possible that only the default context was detroyed and not the second second context?
[ 0.149948] [0000671c] libusb: debug [libusb_unref_device] destroy device 1.7
[ 0.151450] [0000671c] libusb: debug [libusb_exit]
[ 0.151561] [0000671c] libusb: debug [libusb_exit] destroying default context
[ 0.151621] [0000671c] libusb: warning [libusb_exit] some libusb_devices were leaked
Normally the debug log should be something like the following, without the leak warning.
Releasing interface 0...
[ 0.069721] [00003b24] libusb: debug [libusb_release_interface] interface 0
Closing device...
[ 0.069807] [00003b24] libusb: debug [libusb_close]
[ 0.069899] [00003b24] libusb: debug [libusb_unref_device] destroy device 1.12
[ 0.069948] [00003b24] libusb: debug [libusb_unref_device] destroy device 1.0
[ 0.070005] [00003b24] libusb: debug [libusb_exit]
[ 0.070047] [00003b24] libusb: debug [libusb_exit] destroying default context
[ 0.070093] [00003b24] libusb: debug [usbi_remove_event_source] remove HANDLE 00000000000001FC
[ 0.070142] [00003b24] libusb: debug [usbi_remove_event_source] remove HANDLE 00000000000000A4
[ 0.070409] [00003be8] libusb: debug [windows_iocp_thread] I/O completion thread exiting
from python-libusb1.
The following debug log seems to be a bit suspicious. Is it possible that only the default context was detroyed and not the second second context?
Not true. Even if I comment out the following line, it still has the same problem.
#print(usb.is_connected())
from python-libusb1.
This looks like a specific issue with Windows, it may be a libusb issue or a python-libusb1 issue, but more like a python-libusb1 issue to me. I will try out under Linux to see if the issue is there or not.
from python-libusb1.
No issues on libusb under my Linux machine (Raspberry Pi 400 running 64bit Ubuntu Linux ARM).
python_usb on master [?] via 🐍 v3.9.5 ❯ python3 cyusb_fx3_bulkloop_py3_libusb1.py
True
write: True
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
And no leak from the debug log either.
[ 0.060471] [00003943] libusb: debug [libusb_free_transfer] transfer 0x3cf45e40
[ 0.060707] [00003943] libusb: debug [libusb_release_interface] interface 0
[ 0.060834] [00003943] libusb: debug [libusb_close]
[ 0.060862] [00003943] libusb: debug [usbi_remove_event_source] remove fd 7
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
[ 0.061099] [00003943] libusb: debug [libusb_exit]
[ 0.061168] [00003945] libusb: debug [linux_udev_event_thread_main] udev event thread exiting
[ 0.061354] [00003943] libusb: debug [libusb_unref_device] destroy device 3.1
[ 0.061377] [00003943] libusb: debug [libusb_unref_device] destroy device 2.2
[ 0.061392] [00003943] libusb: debug [libusb_unref_device] destroy device 2.1
[ 0.061407] [00003943] libusb: debug [libusb_unref_device] destroy device 1.5
[ 0.061421] [00003943] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.061435] [00003943] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.061451] [00003943] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.061466] [00003943] libusb: debug [usbi_remove_event_source] remove fd 4
[ 0.061494] [00003943] libusb: debug [usbi_remove_event_source] remove fd 3
from python-libusb1.
@vpelletier Since the fault seems to happen because libusb_unref_device() is called after libusb_exit() and that seems to cause problem under Windows (but no problems under Linux), the following dirty hack seems to sort out the issue.
diff --git a/usb1/__init__.py b/usb1/__init__.py
index 0d08688..f131196 100644
--- a/usb1/__init__.py
+++ b/usb1/__init__.py
@@ -1787,9 +1787,9 @@ class USBDevice(object):
closable.close()
if not self.device_p:
return
- self.__libusb_unref_device(self.device_p)
+ # self.__libusb_unref_device(self.device_p)
# pylint: disable=redefined-outer-name
- byref = self.__byref
+ # byref = self.__byref
# pylint: enable=redefined-outer-name
descriptor_list = self.__configuration_descriptor_list
while descriptor_list:
(py39venv) C:\work\libusb\python_usb [master ≡ +8 ~0 -0 !]> python .\cyusb_fx3_bulkloop_py_libusb1.py
True
write: True
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
But of course this does not seem to be the right fix as seen in the warnings of the debug log.
[ 0.147365] [000055d8] libusb: debug [libusb_release_interface] interface 0
[ 0.147480] [000055d8] libusb: debug [libusb_close]
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
[ 0.147793] [000055d8] libusb: debug [libusb_exit]
[ 0.147897] [000052c0] libusb: debug [windows_iocp_thread] I/O completion thread exiting
[ 0.149451] [000055d8] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000130
[ 0.149568] [000055d8] libusb: debug [usbi_remove_event_source] remove HANDLE 000000000000013C
[ 0.149703] [000055d8] libusb: warning [libusb_exit] device 1.28 still referenced
[ 0.149755] [000055d8] libusb: warning [libusb_exit] device 1.4 still referenced
[ 0.149807] [000055d8] libusb: warning [libusb_exit] device 1.40 still referenced
[ 0.149858] [000055d8] libusb: warning [libusb_exit] device 1.15 still referenced
[ 0.149909] [000055d8] libusb: warning [libusb_exit] device 1.6 still referenced
[ 0.149961] [000055d8] libusb: warning [libusb_exit] device 2.0 still referenced
[ 0.150016] [000055d8] libusb: warning [libusb_exit] device 1.0 still referenced
from python-libusb1.
I have raised libusb/libusb#974 to see if libusb can do better, at least for Windows.
from python-libusb1.
Let me try out on the libusb windows side. It is possible that there is an issue there. Thanks.
from python-libusb1.
So far I have not been able to reproduce the issues with libusb yet.
Ref: stress test codes have some simple tests with two contexts.
https://github.com/libusb/libusb/blob/master/tests/stress.c
I have also adapted a few examples with non-default context (but single context) but again I am not able to reproduce the issue. But probably they are not good enough.
C:\work\libusb\libusb [master ≡ +2 ~3 -0 !]> git diff
diff --git a/examples/listdevs.c b/examples/listdevs.c
index b5b027c..5ae5895 100644
--- a/examples/listdevs.c
+++ b/examples/listdevs.c
@@ -54,20 +54,20 @@ int main(void)
libusb_device **devs;
int r;
ssize_t cnt;
-
- r = libusb_init(NULL);
+ libusb_context* ctx = NULL;
+ r = libusb_init(&ctx);
if (r < 0)
return r;
- cnt = libusb_get_device_list(NULL, &devs);
+ cnt = libusb_get_device_list(ctx, &devs);
if (cnt < 0){
- libusb_exit(NULL);
+ libusb_exit(ctx);
return (int) cnt;
}
print_devs(devs);
libusb_free_device_list(devs, 1);
- libusb_exit(NULL);
+ libusb_exit(ctx);
return 0;
}
diff --git a/examples/testlibusb.c b/examples/testlibusb.c
index ba00f90..c44c5d8 100644
--- a/examples/testlibusb.c
+++ b/examples/testlibusb.c
@@ -286,17 +286,17 @@ int main(int argc, char *argv[])
return 1;
}
}
-
- r = libusb_init(NULL);
+ libusb_context* ctx = NULL;
+ r = libusb_init(&ctx);
if (r < 0)
return r;
if (device_name) {
r = test_wrapped_device(device_name);
} else {
- cnt = libusb_get_device_list(NULL, &devs);
+ cnt = libusb_get_device_list(ctx, &devs);
if (cnt < 0) {
- libusb_exit(NULL);
+ libusb_exit(ctx);
return 1;
}
@@ -306,6 +306,6 @@ int main(int argc, char *argv[])
libusb_free_device_list(devs, 1);
}
- libusb_exit(NULL);
+ libusb_exit(ctx);
return r;
}
diff --git a/examples/xusb.c b/examples/xusb.c
index 61ce4dd..e23960a 100644
--- a/examples/xusb.c
+++ b/examples/xusb.c
@@ -1107,13 +1107,14 @@ int main(int argc, char** argv)
version = libusb_get_version();
printf("Using libusb v%d.%d.%d.%d\n\n", version->major, version->minor, version->micro, version->nano);
- r = libusb_init(NULL);
+ libusb_context *ctx = NULL;
+ r = libusb_init(&ctx);
if (r < 0)
return r;
// If not set externally, and no debug option was given, use info log level
if ((old_dbg_str == NULL) && (!debug_mode))
- libusb_set_option(NULL, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_INFO);
+ libusb_set_option(ctx, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_INFO);
if (error_lang != NULL) {
r = libusb_setlocale(error_lang);
if (r < 0)
@@ -1122,7 +1123,7 @@ int main(int argc, char** argv)
test_device(VID, PID);
- libusb_exit(NULL);
+ libusb_exit(ctx);
if (debug_mode) {
snprintf(str, sizeof(str), "LIBUSB_DEBUG=%s", (old_dbg_str == NULL)?"":old_dbg_str);
from python-libusb1.
If we look at the debug log, one strange thing is like the following. There seems to be two times of libusb_get_device_list() and libusb_close() being called.
The following line is commented out here. There is only single libusb context here so context handling does not seem to be the issue.
#print(usb.is_connected())
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000344] [0000507c] libusb: debug [libusb_init] libusb v1.0.24.11650
[ 0.000499] [0000507c] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000654 events 0
[ 0.000668] [0000507c] libusb: debug [usbi_io_init] using timer for timeouts
[ 0.000819] [0000507c] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000650 events 0
[ 0.001003] [0000507c] libusb: debug [get_windows_version] Windows 10 64-bit
[ 0.001156] [0000507c] libusb: debug [htab_create] using 1021 entries hash table
[ 0.004593] [0000507c] libusb: info [winusbx_init] WinUSB DLL available (with isoch support)
[ 0.006318] [0000507c] libusb: debug [winusbx_init] libusbK DLL found, version: 3.1.0.0
[ 0.012722] [0000507c] libusb: debug [windows_init] UsbDk backend is available
[ 0.013124] [0000507c] libusb: debug [libusb_get_device_list]
...
[ 0.057231] [0000507c] libusb: debug [libusb_release_interface] interface 0
[ 0.057314] [0000507c] libusb: debug [libusb_close]
write: True
[ 0.057621] [0000507c] libusb: debug [libusb_get_device_list]
...
...
[ 0.127214] [0000507c] libusb: debug [libusb_release_interface] interface 0
[ 0.127515] [0000507c] libusb: debug [libusb_close]
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
[ 0.128372] [0000507c] libusb: debug [libusb_exit]
[ 0.128646] [00000cbc] libusb: debug [windows_iocp_thread] I/O completion thread exiting
[ 0.132787] [0000507c] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000650
[ 0.133041] [0000507c] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000654
[ 0.133276] [0000507c] libusb: warning [libusb_exit] device 1.8 still referenced
[ 0.133487] [0000507c] libusb: warning [libusb_exit] device 1.0 still referenced
[ 0.137786] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.8
click to expand
(py39venv) C:\work\libusb\python_usb [master ≡ +8 ~0 -0 !]> $Env:LIBUSB_DEBUG=4
(py39venv) C:\work\libusb\python_usb [master ≡ +8 ~0 -0 !]> python .\cyusb_fx3_loopback_python_libusb1.py
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000344] [0000507c] libusb: debug [libusb_init] libusb v1.0.24.11650
[ 0.000499] [0000507c] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000654 events 0
[ 0.000668] [0000507c] libusb: debug [usbi_io_init] using timer for timeouts
[ 0.000819] [0000507c] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000650 events 0
[ 0.001003] [0000507c] libusb: debug [get_windows_version] Windows 10 64-bit
[ 0.001156] [0000507c] libusb: debug [htab_create] using 1021 entries hash table
[ 0.004593] [0000507c] libusb: info [winusbx_init] WinUSB DLL available (with isoch support)
[ 0.006318] [0000507c] libusb: debug [winusbx_init] libusbK DLL found, version: 3.1.0.0
[ 0.012722] [0000507c] libusb: debug [windows_init] UsbDk backend is available
[ 0.013124] [0000507c] libusb: debug [libusb_get_device_list]
[ 0.014244] [00000cbc] libusb: debug [windows_iocp_thread] I/O completion thread started
[ 0.034398] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [93]
[ 0.034668] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [94]
[ 0.035065] [0000507c] libusb: debug [get_api_type] driver(s): BTHUSB
[ 0.035234] [0000507c] libusb: debug [get_api_type] lower filter driver(s): ibtusb
[ 0.035339] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [10]
[ 0.035630] [0000507c] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.035765] [0000507c] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.035866] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [1E]
[ 0.036349] [0000507c] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.036485] [0000507c] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.036584] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [71]
[ 0.036828] [0000507c] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.036963] [0000507c] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.037064] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [72]
[ 0.037311] [0000507c] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.037442] [0000507c] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.037534] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [73]
[ 0.037850] [0000507c] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.038012] [0000507c] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.038118] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [74]
[ 0.038546] [0000507c] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_A36D&SUBSYS_091A1028&REV_10\3&11583659&0&A0' bus number 1
[ 0.038820] [0000507c] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_15DB&SUBSYS_091A1028&REV_02\71D9F51854B3020000' bus number 2
[ 0.041156] [0000507c] libusb: debug [winusb_get_device_list] extra GUID: {865C4DDE-10B6-6373-FAEE-1506B321A619}
[ 0.041340] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [71]
[ 0.041521] [0000507c] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.041634] [0000507c] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 59 bytes)
[ 0.041787] [0000507c] libusb: debug [init_device] (bus: 1, addr: 1, depth: 1, port: 3): 'USB\VID_046D&PID_C534\5&E9F3E45&0&3'
[ 0.042027] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [10]
[ 0.042198] [0000507c] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.042283] [0000507c] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 200 bytes)
[ 0.042366] [0000507c] libusb: debug [init_device] (bus: 1, addr: 3, depth: 1, port: 14): 'USB\VID_8087&PID_0AAA\5&E9F3E45&0&14'
[ 0.042782] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [74]
[ 0.042955] [0000507c] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.043039] [0000507c] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 288 bytes)
[ 0.043153] [0000507c] libusb: debug [init_device] (bus: 1, addr: 5, depth: 1, port: 2): 'USB\VID_047F&PID_C056\D1CEC32927974D5F9BD6B2AEBF2EA8E3'
[ 0.043612] [0000507c] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\4&36020D6F&0&0' reports 26 ports
[ 0.043791] [0000507c] libusb: debug [init_device] (bus: 1, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\4&36020D6F&0&0'
[ 0.043983] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [73]
[ 0.044215] [0000507c] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.044305] [0000507c] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 269 bytes)
[ 0.044387] [0000507c] libusb: debug [init_device] (bus: 1, addr: 4, depth: 1, port: 10): 'USB\VID_0A5C&PID_5842\0123456789ABCD'
[ 0.044825] [0000507c] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\7&2452366F&0&0' reports 4 ports
[ 0.044929] [0000507c] libusb: debug [init_device] (bus: 2, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\7&2452366F&0&0'
[ 0.045254] [0000507c] libusb: debug [winusb_get_device_list] extra GUID: {209D0288-9C4C-5B63-3A38-9EBE14E03F48}
[ 0.045340] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [1E]
[ 0.045481] [0000507c] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.045568] [0000507c] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 44 bytes)
[ 0.045682] [0000507c] libusb: debug [init_device] (bus: 1, addr: 8, depth: 1, port: 17): 'USB\VID_04B4&PID_00F0\5&E9F3E45&0&17'
[ 0.046217] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [72]
[ 0.046391] [0000507c] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.046507] [0000507c] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 1112 bytes)
[ 0.046669] [0000507c] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 11): 'USB\VID_0BDA&PID_58FD\200901010001'
[ 0.047220] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL01\7&290AACAE&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.047412] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.047496] [0000507c] libusb: debug [set_composite_interface] interface[1] = \\?\HID#VID_046D&PID_C534&MI_01&COL01#7&383A3A17&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.047645] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL01\5&99B72D3&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.047809] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.047914] [0000507c] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL03\7&383A3A17&0&0002
[ 0.048044] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL03\5&379854AA&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.048191] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.048261] [0000507c] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL02\7&383A3A17&0&0001
[ 0.048358] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.048432] [0000507c] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL04\7&383A3A17&0&0003
[ 0.048539] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL01\3&36A7043C&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.048674] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL02\7&290AACAE&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.048795] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.048868] [0000507c] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL05\7&383A3A17&0&0004
[ 0.048968] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL02\3&36A7043C&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.049101] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL02\5&99B72D3&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.049248] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.049295] [0000507c] libusb: debug [set_composite_interface] interface[3] = \\?\HID#VID_047F&PID_C056&MI_03&COL01#F&39E6F119&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.049399] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL02\5&379854AA&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.049543] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.049634] [0000507c] libusb: debug [set_composite_interface] interface[3] already set - ignoring HID collection: HID\VID_047F&PID_C056&MI_03&COL02\F&39E6F119&0&0001
[ 0.049742] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.049789] [0000507c] libusb: debug [set_composite_interface] interface[3] already set - ignoring HID collection: HID\VID_047F&PID_C056&MI_03&COL03\F&39E6F119&0&0002
[ 0.049892] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL03\5&99B72D3&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.050310] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.050382] [0000507c] libusb: debug [set_composite_interface] interface[0] = \\?\HID#VID_046D&PID_C534&MI_00#7&1C54B96&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}\KBD
[ 0.050504] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL04\5&99B72D3&0&0003' (non USB HID, newly connected, etc.) - ignoring
[ 0.050664] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL05\5&99B72D3&0&0004' (non USB HID, newly connected, etc.) - ignoring
[ 0.050830] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL01\5&379854AA&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.052014] [0000507c] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.052170] [0000507c] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.053055] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.053189] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.053428] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.053539] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.053668] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.053749] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.053828] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x25
[ 0.053900] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x25
[ 0.053980] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.054059] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.054138] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.054248] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.054347] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.054456] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.054573] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.054652] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.054770] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.054850] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.054927] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.055007] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.055084] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.055169] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.055247] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.5
[ 0.055298] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.055345] [0000507c] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.055391] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.055531] [0000507c] libusb: debug [libusb_open] open 1.8
[ 0.055636] [0000507c] libusb: debug [libusb_claim_interface] interface 0
[ 0.055763] [0000507c] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.055813] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.055904] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.055956] [0000507c] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 01 to interface 0
[ 0.056004] [0000507c] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.056223] [0000507c] libusb: debug [libusb_submit_transfer] transfer 000001BD8F37DCF8
[ 0.056277] [0000507c] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 01 with interface 0
[ 0.056328] [0000507c] libusb: debug [winusbx_submit_bulk_transfer] writing 100 bytes
[ 0.056470] [0000507c] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.056524] [0000507c] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.056579] [0000507c] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.056578] [00000cbc] libusb: debug [windows_iocp_thread] transfer 000001BD8F37DCF8 completed, length 100
[ 0.056815] [0000507c] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.056867] [0000507c] libusb: debug [handle_event_trigger] event triggered
[ 0.056918] [0000507c] libusb: debug [windows_handle_transfer_completion] handling transfer 000001BD8F37DCF8 completion with errcode 0, length 100
[ 0.057018] [0000507c] libusb: debug [usbi_handle_transfer_completion] transfer 000001BD8F37DCF8 has callback 00007FFB31409220
[ 0.057093] [0000507c] libusb: debug [sync_transfer_cb] actual_length=100
[ 0.057143] [0000507c] libusb: debug [libusb_free_transfer] transfer 000001BD8F37DCF8
[ 0.057231] [0000507c] libusb: debug [libusb_release_interface] interface 0
[ 0.057314] [0000507c] libusb: debug [libusb_close]
write: True
[ 0.057621] [0000507c] libusb: debug [libusb_get_device_list]
[ 0.077004] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [93]
[ 0.077229] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [94]
[ 0.077602] [0000507c] libusb: debug [get_api_type] driver(s): BTHUSB
[ 0.077800] [0000507c] libusb: debug [get_api_type] lower filter driver(s): ibtusb
[ 0.077956] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [10]
[ 0.078312] [0000507c] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.078502] [0000507c] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.078605] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [1E]
[ 0.079255] [0000507c] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.079470] [0000507c] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.079574] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [71]
[ 0.079883] [0000507c] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.080021] [0000507c] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.080122] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [72]
[ 0.080382] [0000507c] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.080499] [0000507c] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.080600] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [73]
[ 0.080934] [0000507c] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.081132] [0000507c] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.081275] [0000507c] libusb: debug [winusb_get_device_list] allocating new device for session [74]
[ 0.081668] [0000507c] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_15DB&SUBSYS_091A1028&REV_02\71D9F51854B3020000' bus number 2
[ 0.083495] [0000507c] libusb: debug [winusb_get_device_list] extra GUID: {865C4DDE-10B6-6373-FAEE-1506B321A619}
[ 0.083618] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [71]
[ 0.083842] [0000507c] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.083957] [0000507c] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 59 bytes)
[ 0.084111] [0000507c] libusb: debug [init_device] (bus: 1, addr: 1, depth: 1, port: 3): 'USB\VID_046D&PID_C534\5&E9F3E45&0&3'
[ 0.084370] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [10]
[ 0.084562] [0000507c] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.084727] [0000507c] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 200 bytes)
[ 0.084881] [0000507c] libusb: debug [init_device] (bus: 1, addr: 3, depth: 1, port: 14): 'USB\VID_8087&PID_0AAA\5&E9F3E45&0&14'
[ 0.085356] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [74]
[ 0.085548] [0000507c] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.085661] [0000507c] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 288 bytes)
[ 0.085806] [0000507c] libusb: debug [init_device] (bus: 1, addr: 5, depth: 1, port: 2): 'USB\VID_047F&PID_C056\D1CEC32927974D5F9BD6B2AEBF2EA8E3'
[ 0.086345] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [73]
[ 0.086514] [0000507c] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.086598] [0000507c] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 269 bytes)
[ 0.086713] [0000507c] libusb: debug [init_device] (bus: 1, addr: 4, depth: 1, port: 10): 'USB\VID_0A5C&PID_5842\0123456789ABCD'
[ 0.087164] [0000507c] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\7&2452366F&0&0' reports 4 ports
[ 0.087271] [0000507c] libusb: debug [init_device] (bus: 2, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\7&2452366F&0&0'
[ 0.087591] [0000507c] libusb: debug [winusb_get_device_list] extra GUID: {209D0288-9C4C-5B63-3A38-9EBE14E03F48}
[ 0.087688] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [1E]
[ 0.088478] [0000507c] libusb: debug [winusb_get_device_list] found existing device for session [72]
[ 0.088739] [0000507c] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.088877] [0000507c] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 1112 bytes)
[ 0.089041] [0000507c] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 11): 'USB\VID_0BDA&PID_58FD\200901010001'
[ 0.089498] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL01\7&290AACAE&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.089643] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.089775] [0000507c] libusb: debug [set_composite_interface] interface[1] = \\?\HID#VID_046D&PID_C534&MI_01&COL01#7&383A3A17&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.089945] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL01\5&99B72D3&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.090102] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.090176] [0000507c] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL03\7&383A3A17&0&0002
[ 0.090381] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL03\5&379854AA&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.090522] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.090599] [0000507c] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL02\7&383A3A17&0&0001
[ 0.090713] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.090793] [0000507c] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL04\7&383A3A17&0&0003
[ 0.090960] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL01\3&36A7043C&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.091237] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL02\7&290AACAE&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.091437] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.091559] [0000507c] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL05\7&383A3A17&0&0004
[ 0.091737] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL02\3&36A7043C&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.091922] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL02\5&99B72D3&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.092110] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.092235] [0000507c] libusb: debug [set_composite_interface] interface[3] = \\?\HID#VID_047F&PID_C056&MI_03&COL01#F&39E6F119&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.092400] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL02\5&379854AA&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.092509] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.092559] [0000507c] libusb: debug [set_composite_interface] interface[3] already set - ignoring HID collection: HID\VID_047F&PID_C056&MI_03&COL02\F&39E6F119&0&0001
[ 0.092660] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.092707] [0000507c] libusb: debug [set_composite_interface] interface[3] already set - ignoring HID collection: HID\VID_047F&PID_C056&MI_03&COL03\F&39E6F119&0&0002
[ 0.092813] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL03\5&99B72D3&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.092913] [0000507c] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.092964] [0000507c] libusb: debug [set_composite_interface] interface[0] = \\?\HID#VID_046D&PID_C534&MI_00#7&1C54B96&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}\KBD
[ 0.093136] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL04\5&99B72D3&0&0003' (non USB HID, newly connected, etc.) - ignoring
[ 0.093256] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL05\5&99B72D3&0&0004' (non USB HID, newly connected, etc.) - ignoring
[ 0.093369] [0000507c] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL01\5&379854AA&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.094467] [0000507c] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.094567] [0000507c] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.095349] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.095412] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.095506] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.095557] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.095647] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.095749] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.095835] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x25
[ 0.095889] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x25
[ 0.095973] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.096025] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.096071] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.096141] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.096192] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.096268] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.096317] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.096362] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.096431] [0000507c] libusb: debug [libusb_get_device_descriptor]
[ 0.096480] [0000507c] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.096526] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.096568] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.096641] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.096689] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.096733] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.5
[ 0.096777] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.096821] [0000507c] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.096865] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.096940] [0000507c] libusb: debug [libusb_open] open 1.8
[ 0.097032] [0000507c] libusb: debug [libusb_claim_interface] interface 0
[ 0.097143] [0000507c] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.097192] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.097234] [0000507c] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.097278] [0000507c] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 01 to interface 0
[ 0.097323] [0000507c] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.097490] [0000507c] libusb: debug [libusb_submit_transfer] transfer 000001BD8F37DCF8
[ 0.097538] [0000507c] libusb: debug [add_to_flying_list] arm timer for timeout in 10ms (first in line)
[ 0.097591] [0000507c] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 81 with interface 0
[ 0.097637] [0000507c] libusb: debug [winusbx_submit_bulk_transfer] reading 1024 bytes
[ 0.097714] [0000507c] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.097821] [0000507c] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.097780] [00000cbc] libusb: debug [windows_iocp_thread] transfer 000001BD8F37DCF8 completed, length 100
[ 0.098120] [0000507c] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.098213] [0000507c] libusb: debug [handle_event_trigger] event triggered
[ 0.098262] [0000507c] libusb: debug [windows_handle_transfer_completion] handling transfer 000001BD8F37DCF8 completion with errcode 0, length 100
[ 0.098340] [0000507c] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.098395] [0000507c] libusb: debug [usbi_handle_transfer_completion] transfer 000001BD8F37DCF8 has callback 00007FFB31409220
[ 0.098532] [0000507c] libusb: debug [sync_transfer_cb] actual_length=100
[ 0.098582] [0000507c] libusb: debug [libusb_free_transfer] transfer 000001BD8F37DCF8
[ 0.098670] [0000507c] libusb: debug [libusb_submit_transfer] transfer 000001BD8F482748
[ 0.098773] [0000507c] libusb: debug [add_to_flying_list] arm timer for timeout in 10ms (first in line)
[ 0.098832] [0000507c] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 81 with interface 0
[ 0.098885] [0000507c] libusb: debug [winusbx_submit_bulk_transfer] reading 1024 bytes
[ 0.098958] [0000507c] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.099059] [0000507c] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.123864] [0000507c] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 1
[ 0.124105] [0000507c] libusb: debug [libusb_cancel_transfer] transfer 000001BD8F482748
[ 0.124391] [0000507c] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.124557] [00000cbc] libusb: debug [windows_iocp_thread] transfer 000001BD8F482748 completed, length 0
[ 0.124636] [0000507c] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.125193] [0000507c] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.125506] [0000507c] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.125650] [0000507c] libusb: debug [handle_event_trigger] event triggered
[ 0.125787] [0000507c] libusb: debug [windows_handle_transfer_completion] handling transfer 000001BD8F482748 completion with errcode 995, length 0
[ 0.126085] [0000507c] libusb: debug [windows_handle_transfer_completion] detected operation aborted
[ 0.126216] [0000507c] libusb: debug [usbi_handle_transfer_cancellation] detected timeout cancellation
[ 0.126373] [0000507c] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.126502] [0000507c] libusb: debug [usbi_handle_transfer_completion] transfer 000001BD8F482748 has callback 00007FFB31409220
[ 0.126774] [0000507c] libusb: debug [sync_transfer_cb] actual_length=0
[ 0.126897] [0000507c] libusb: debug [libusb_free_transfer] transfer 000001BD8F482748
[ 0.127214] [0000507c] libusb: debug [libusb_release_interface] interface 0
[ 0.127515] [0000507c] libusb: debug [libusb_close]
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
[ 0.128372] [0000507c] libusb: debug [libusb_exit]
[ 0.128646] [00000cbc] libusb: debug [windows_iocp_thread] I/O completion thread exiting
[ 0.132787] [0000507c] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000650
[ 0.133041] [0000507c] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000654
[ 0.133276] [0000507c] libusb: warning [libusb_exit] device 1.8 still referenced
[ 0.133487] [0000507c] libusb: warning [libusb_exit] device 1.0 still referenced
[ 0.137786] [0000507c] libusb: debug [libusb_unref_device] destroy device 1.8
Exception ignored in: <function USBDevice.__del__ at 0x000001BD8F7A8820>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1778, in __del__
self.close()
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1790, in close
self.__libusb_unref_device(self.device_p)
OSError: exception: access violation writing 0x0000000000000024
from python-libusb1.
Adding some debug print.
(py39venv) C:\work\libusb\python_usb [master ≡ +8 ~0 -0 !]> python .\cyusb_fx3_loopback_python_libusb1.py
write: True
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
Closing USB
Close handle successfully
Exception ignored in: <function USBDevice.__del__ at 0x000001AF13268820>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1778, in __del__
self.close()
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1790, in close
self.__libusb_unref_device(self.device_p)
OSError: exception: access violation writing 0x0000000000000024
Calling closing method to delete self
Closing USB
Close handle successfully
import usb1
class USB:
"""USB class that handles IO operation with USB device
ENDPOINT_IN: device-to-host, ENDPOINT_OUT: host-to-device"""
# read size chunk
READ_CHUNK = 1024
def __init__(self, pid: hex, vid: hex, endpoint_in: hex, endpoint_out: hex) -> None:
self.endpoint_in = endpoint_in
self.endpoint_out = endpoint_out
self.pid = pid
self.vid = vid
self.context = usb1.USBContext()
def is_connected(self) -> bool:
"""Check if specified device is connected"""
with usb1.USBContext() as context:
for device in context.getDeviceIterator(skip_on_error=True):
if device.getVendorID() == self.vid and device.getProductID() == self.pid:
return True
def open(self) -> bool:
"""Open USB and initialize interface"""
try:
self.context.open()
return True
except Exception as err:
print("open device error:", err)
return False
def __get_handle(self):
"""return handle object"""
return self.context.openByVendorIDAndProductID(self.vid, self.pid)
def close(self) -> bool:
"""Close USB"""
print("Closing USB")
try:
self.context.close()
print("Close handle successfully")
return True
except Exception as err:
print("Close handle error:", err)
return False
def write(self, msg: bytearray, timeout: int = 0) -> bool:
"""write an specific msg to device"""
handle = self.__get_handle()
if not handle:
return False
try:
with handle.claimInterface(0):
bytes_written = handle.bulkWrite(
self.endpoint_out, msg, timeout)
return bytes_written == len(msg)
except Exception as err:
print("write error", err)
handle.close()
return False
def read(self, timeout: int = 10) -> bytearray:
"""read data from the device"""
data = bytearray()
handle = self.__get_handle()
if not handle:
return False
try:
with handle.claimInterface(0):
while True:
try:
data += handle.bulkRead(self.endpoint_in,
self.READ_CHUNK, timeout)
except usb1.USBErrorTimeout:
break
except Exception as err:
print("read error", err)
return None
handle.close()
return data
def __del__(self):
print("Calling closing method to delete self")
self.close()
if __name__ == '__main__':
VENDOR_ID = 0x04b4
PRODUCT_ID = 0x00f0
ENDPOINT_IN = 0x81
ENDPOINT_OUT = 0x01
usb = USB(PRODUCT_ID, VENDOR_ID, ENDPOINT_IN, ENDPOINT_OUT)
#print(usb.is_connected())
msg = 100 * bytearray(b"B")
if usb.open():
print("write:", usb.write(msg))
print("read:", usb.read())
# error after adding this line
usb.close()
from python-libusb1.
If we look at the debug log, one strange thing is like the following. There seems to be two times of libusb_get_device_list() and libusb_close() being called.
There is one special thing about libusb_get_device_list
: it is called in a generator method, getDeviceIterator
. I believe generators which are exhausted exit synchronously, but those which stop being used mid-sequence rely on garbage collection to close them, which then causes the pending (see EDIT below), which then (normally) causes the generator function to end.yield
statement to raise StopIteration
EDIT: This is apparently not actually the case, the code somehow jumps to any finally
block surrounding the active yield
statement without an exception being visible to the interpreter (sys.exc_info() == (None, None, None)
).
I do not see yet why libusb_get_device_list
would end up being called a second time, but I am getting the idea that there can be something wrong with context cleanup order while one such generator is stuck in limbo for the gc to clean it up.
One way to check this could be to call getDeviceList
instead of openByVendorIDAndProductID
, and basically duplicating the device matching logic: getDeviceList
exhausts the iterator.
from python-libusb1.
Could you give a try to the following patch ? The context refcount wrapper (being patched here) can return before getDeviceIterator
does (because of collection order). This should force getDeviceIterator
to exit before the context refcount can be decremented. So I think this patch fixes a bug, I just do not know if it is related to this issue.
diff --git a/usb1/__init__.py b/usb1/__init__.py
index 1648124..6cd33cb 100644
--- a/usb1/__init__.py
+++ b/usb1/__init__.py
@@ -2085,9 +2085,13 @@ class USBContext(object):
with refcount(self):
if self.__context_p:
# pylint: disable=not-callable
- for value in func(self, *args, **kw):
- # pylint: enable=not-callable
- yield value
+ generator = func(self, *args, **kw)
+ # pylint: enable=not-callable
+ try:
+ for value in generator:
+ yield value
+ finally:
+ generator.close()
else:
def wrapper(self, *args, **kw):
with refcount(self):
from python-libusb1.
...and I just noticed that your code calls
__get_handle
twice (once inwrite
and once inread
). This should explain the duplicatelibusb_get_device_list
call. It does not exclude an iterator lifetime issue, so I will poke a bit more at this.
Thanks. I think this is the root cause of the issue.
If I delete the read function, then there is no issue.
(py39venv) C:\work\libusb\python_usb [master ≡ +7 ~0 -0 !]> pip show libusb1
Name: libusb1
Version: 1.9.3
Summary: Pure-python wrapper for libusb-1.0
Home-page: http://github.com/vpelletier/python-libusb1
Author: Vincent Pelletier
Author-email: [email protected]
License: LGPLv2.1+
Location: c:\work\python\py39venv\lib\site-packages
Requires:
Required-by:
(py39venv) C:\work\libusb\python_usb [master ≡ +7 ~0 -0 !]> cat .\cyusb_fx3_bulkloop_python_libusb1_write.py
# codes from https://github.com/vpelletier/python-libusb1/issues/72
import usb1
class USB:
"""USB class that handles IO operation with USB device
ENDPOINT_IN: device-to-host, ENDPOINT_OUT: host-to-device"""
# read size chunk
READ_CHUNK = 1024
def __init__(self, pid: hex, vid: hex, endpoint_in: hex, endpoint_out: hex) -> None:
self.endpoint_in = endpoint_in
self.endpoint_out = endpoint_out
self.pid = pid
self.vid = vid
self.context = usb1.USBContext()
def is_connected(self) -> bool:
"""Check if specified device is connected"""
with usb1.USBContext() as context:
for device in context.getDeviceIterator(skip_on_error=True):
if device.getVendorID() == self.vid and device.getProductID() == self.pid:
return True
def open(self) -> bool:
"""Open USB and initialize interface"""
try:
self.context.open()
return True
except Exception as err:
print("open device error:", err)
return False
def __get_handle(self):
"""return handle object"""
return self.context.openByVendorIDAndProductID(self.vid, self.pid)
def close(self) -> bool:
"""Close USB"""
print("Closing USB")
try:
self.context.close()
print("Close handle successfully")
return True
except Exception as err:
print("Close handle error:", err)
return False
def write(self, msg: bytearray, timeout: int = 0) -> bool:
"""write an specific msg to device"""
handle = self.__get_handle()
if not handle:
return False
try:
with handle.claimInterface(0):
bytes_written = handle.bulkWrite(
self.endpoint_out, msg, timeout)
bytes_written == len(msg)
print("Number of bytes written: ", bytes_written)
return True
except Exception as err:
print("write error", err)
handle.close()
return False
def __del__(self):
print("Calling closing method to delete self")
self.close()
if __name__ == '__main__':
VENDOR_ID = 0x04b4
PRODUCT_ID = 0x00f0
ENDPOINT_IN = 0x81
ENDPOINT_OUT = 0x01
usb = USB(PRODUCT_ID, VENDOR_ID, ENDPOINT_IN, ENDPOINT_OUT)
#print(usb.is_connected())
msg = 1024 * bytearray(b"B")
if usb.open():
print("write:", usb.write(msg))
# error after adding this line
usb.close()
(py39venv) C:\work\libusb\python_usb [master ≡ +7 ~0 -0 !]> python .\cyusb_fx3_bulkloop_python_libusb1_write.py
Number of bytes written: 1024
write: True
Closing USB
Close handle successfully
Calling closing method to delete self
Closing USB
Close handle successfully
from python-libusb1.
Could you give a try to the following patch ? The context refcount wrapper (being patched here) can return before
getDeviceIterator
does (because of collection order). This should forcegetDeviceIterator
to exit before the context refcount can be decremented. So I think this patch fixes a bug, I just do not know if it is related to this issue.
This does not seem to help.
(py39venv) C:\work\libusb\python-libusb1 [master ≡ +1 ~1 -0 !]> pip install .
Processing c:\work\libusb\python-libusb1
DEPRECATION: A future pip version will change local packages to be built in-place without first copying to a temporary directory. We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default.
pip 21.3 will remove support for this functionality. You can find discussion regarding this at https://github.com/pypa/pip/issues/7555.
Building wheels for collected packages: libusb1
Building wheel for libusb1 (setup.py) ... done
Created wheel for libusb1: filename=libusb1-1.9.3+1.gae29a07.dirty-py3-none-any.whl size=60830 sha256=ba2cf9602c6bd831bbdd336387180292e1647ce41d0693201d469059093e9a0f
Stored in directory: c:\users\xfchen\appdata\local\pip\cache\wheels\b5\26\d7\725d45eae9e6667265a6409639f86f7f1b5bec0756a4c9f5e9
Successfully built libusb1
Installing collected packages: libusb1
Attempting uninstall: libusb1
Found existing installation: libusb1 1.9.3
Uninstalling libusb1-1.9.3:
Successfully uninstalled libusb1-1.9.3
Successfully installed libusb1-1.9.3+1.gae29a07.dirty
(py39venv) C:\work\libusb\python_usb [master ≡ +5 ~1 -0 !]> python .\cyusb_fx3_bulkloop_python_libusb1.py
write: True
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
Closing USB
Close handle successfully
Exception ignored in: <function USBDevice.__del__ at 0x0000029F57258940>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1778, in __del__
self.close()
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1790, in close
self.__libusb_unref_device(self.device_p)
OSError: exception: access violation writing 0x0000000000000024
Calling closing method to delete self
Closing USB
Close handle successfully
from python-libusb1.
Here is the quick hack but working codes with only single __get_handle call. Take note I remove the exception handlings to make it easy for me.
(py39venv) C:\work\libusb\python_usb [master ≡ +7 ~1 -0 !]> cat .\cyusb_fx3_bulkloop_python_libusb1_write_read.py
# codes from https://github.com/vpelletier/python-libusb1/issues/72
import usb1
class USB:
"""USB class that handles IO operation with USB device
ENDPOINT_IN: device-to-host, ENDPOINT_OUT: host-to-device"""
# read size chunk
READ_CHUNK = 1024
def __init__(self, pid: hex, vid: hex, endpoint_in: hex, endpoint_out: hex) -> None:
self.endpoint_in = endpoint_in
self.endpoint_out = endpoint_out
self.pid = pid
self.vid = vid
self.context = usb1.USBContext()
def is_connected(self) -> bool:
"""Check if specified device is connected"""
with usb1.USBContext() as context:
for device in context.getDeviceIterator(skip_on_error=True):
if device.getVendorID() == self.vid and device.getProductID() == self.pid:
return True
def open(self) -> bool:
"""Open USB and initialize interface"""
try:
self.context.open()
return True
except Exception as err:
print("open device error:", err)
return False
def __get_handle(self):
"""return handle object"""
return self.context.openByVendorIDAndProductID(self.vid, self.pid)
def close(self) -> bool:
"""Close USB"""
print("Closing USB")
try:
self.context.close()
print("Close handle successfully")
return True
except Exception as err:
print("Close handle error:", err)
return False
def write_read(self, msg: bytearray, timeout: int = 0) -> bytearray:
"""write an specific msg to device and then read"""
data = bytearray()
handle = self.__get_handle()
with handle.claimInterface(0):
handle.bulkWrite(self.endpoint_out, msg, timeout)
bytes_written = len(msg)
print("Number of bytes written: ", bytes_written)
data += handle.bulkRead(self.endpoint_in,
self.READ_CHUNK, timeout)
handle.close()
return data
def __del__(self):
print("Calling closing method to delete self")
self.close()
if __name__ == '__main__':
VENDOR_ID = 0x04b4
PRODUCT_ID = 0x00f0
ENDPOINT_IN = 0x81
ENDPOINT_OUT = 0x01
usb = USB(PRODUCT_ID, VENDOR_ID, ENDPOINT_IN, ENDPOINT_OUT)
#print(usb.is_connected())
msg = 100 * bytearray(b"B")
if usb.open():
print("Reading back:", usb.write_read(msg))
# error after adding this line
usb.close()
(py39venv) C:\work\libusb\python_usb [master ≡ +7 ~1 -0 !]> python .\cyusb_fx3_bulkloop_python_libusb1_write_read.py
Number of bytes written: 100
Reading back: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
Closing USB
Close handle successfully
Calling closing method to delete self
Closing USB
Close handle successfully
from python-libusb1.
libusb/libusb#974 (comment)
libusb/libusb#988
I have some simple codes to show device still referenced upon libusb_exit under Windows. Need to check if it is a libusb Windows issue or not. And I am not so sure if it is related to this issue or not.
from python-libusb1.
Thanks. I think this is the root cause of the issue.
Well, it's definitely interesting to know it makes a difference, but I think it should not be the root cause. In the sense that it should be fine to list and open the device multiple times, at least as long as there is no overlap in the time both are opened. So while the pattern of list-open-read/write-close and then doing it all over again is not exactly typical (I would consider list-open-read/write-read/write-...-close to be more typical), at least I do not identify anything fundamentally wrong with it. So there has to be something actually wrong being triggered by this unusual pattern and causing the access violation.
from python-libusb1.
I tend to believe there is an issue with libusb Windows as mentioned in libusb/libusb#974 and libusb/libusb/#988 with regard to device reference leak problem. It seems to me the issue has always been there under libusb Windows (tested back to libusb-1.0.21 release).
On the other hand, I tend to think the "access violation" may be related to how python-libusb1 works. Just wondering if python-libusb1 has some debug logging feature which I can use to debug further. Thanks.
from python-libusb1.
Nice findings. I change the main function to include gc.collect() and indeed the issues go away.
if __name__ == '__main__':
import gc
#gc.enable()
VENDOR_ID = 0x04b4
PRODUCT_ID = 0x00f0
ENDPOINT_IN = 0x81
ENDPOINT_OUT = 0x01
usb = USB(PRODUCT_ID, VENDOR_ID, ENDPOINT_IN, ENDPOINT_OUT)
#print(usb.is_connected())
msg = 100 * bytearray(b"B")
if usb.open():
print("write:", usb.write(msg))
gc.collect()
print("read:", usb.read())
gc.collect()
# error after adding this line
usb.close()
(py39venv) C:\work\libusb\python_usb [master ≡ +8 ~1 -0 !]> python .\cyusb_fx3_bulkloop_python_libusb1_debug.py
Number of bytes written: 100
write: True
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
Closing USB
Close handle successfully
Calling closing method to delete self
Closing USB
Close handle successfully
Debug log:
click to expand for the full debug log
(py39venv) C:\work\libusb\python_usb [master ≡ +8 ~1 -0 !]> $Env:LIBUSB_DEBUG=4
(py39venv) C:\work\libusb\python_usb [master ≡ +8 ~1 -0 !]> python .\cyusb_fx3_bulkloop_python_libusb1_debug.py
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000281] [000043c8] libusb: debug [libusb_init] libusb v1.0.24.11650
[ 0.000414] [000043c8] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000644 events 0
[ 0.000522] [000043c8] libusb: debug [usbi_io_init] using timer for timeouts
[ 0.000578] [000043c8] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000648 events 0
[ 0.000653] [000043c8] libusb: debug [get_windows_version] Windows 10 64-bit
[ 0.000760] [000043c8] libusb: debug [htab_create] using 1021 entries hash table
[ 0.003491] [000043c8] libusb: info [winusbx_init] WinUSB DLL available (with isoch support)
[ 0.004529] [000043c8] libusb: debug [winusbx_init] libusbK DLL found, version: 3.1.0.0
[ 0.010269] [000043c8] libusb: debug [windows_init] UsbDk backend is available
[ 0.010614] [000043c8] libusb: debug [libusb_get_device_list]
[ 0.012063] [0000097c] libusb: debug [windows_iocp_thread] I/O completion thread started
[ 0.031902] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [93]
[ 0.032103] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [94]
[ 0.032480] [000043c8] libusb: debug [get_api_type] driver(s): BTHUSB
[ 0.032650] [000043c8] libusb: debug [get_api_type] lower filter driver(s): ibtusb
[ 0.032754] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [10]
[ 0.033045] [000043c8] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.033182] [000043c8] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.033280] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [1E]
[ 0.033761] [000043c8] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.033894] [000043c8] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.033993] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [71]
[ 0.034237] [000043c8] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.034370] [000043c8] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.034471] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [72]
[ 0.034717] [000043c8] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.034847] [000043c8] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.034945] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [73]
[ 0.035193] [000043c8] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.035324] [000043c8] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.035423] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [74]
[ 0.035717] [000043c8] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_A36D&SUBSYS_091A1028&REV_10\3&11583659&0&A0' bus number 1
[ 0.035894] [000043c8] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_15DB&SUBSYS_091A1028&REV_02\71D9F51854B3020000' bus number 2
[ 0.037573] [000043c8] libusb: debug [winusb_get_device_list] extra GUID: {865C4DDE-10B6-6373-FAEE-1506B321A619}
[ 0.037751] [000043c8] libusb: debug [winusb_get_device_list] found existing device for session [71]
[ 0.038033] [000043c8] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.038191] [000043c8] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 59 bytes)
[ 0.038355] [000043c8] libusb: debug [init_device] (bus: 1, addr: 3, depth: 1, port: 3): 'USB\VID_046D&PID_C534\5&E9F3E45&0&3'
[ 0.038673] [000043c8] libusb: debug [winusb_get_device_list] found existing device for session [10]
[ 0.038891] [000043c8] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.039005] [000043c8] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 200 bytes)
[ 0.039163] [000043c8] libusb: debug [init_device] (bus: 1, addr: 5, depth: 1, port: 14): 'USB\VID_8087&PID_0AAA\5&E9F3E45&0&14'
[ 0.039712] [000043c8] libusb: debug [winusb_get_device_list] found existing device for session [74]
[ 0.039913] [000043c8] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.040023] [000043c8] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 288 bytes)
[ 0.040176] [000043c8] libusb: debug [init_device] (bus: 1, addr: 30, depth: 1, port: 2): 'USB\VID_047F&PID_C056\D1CEC32927974D5F9BD6B2AEBF2EA8E3'
[ 0.040732] [000043c8] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\4&36020D6F&0&0' reports 26 ports
[ 0.040957] [000043c8] libusb: debug [init_device] (bus: 1, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\4&36020D6F&0&0'
[ 0.041184] [000043c8] libusb: debug [winusb_get_device_list] found existing device for session [73]
[ 0.041377] [000043c8] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.041486] [000043c8] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 269 bytes)
[ 0.041637] [000043c8] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 10): 'USB\VID_0A5C&PID_5842\0123456789ABCD'
[ 0.042234] [000043c8] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\7&2452366F&0&0' reports 4 ports
[ 0.042342] [000043c8] libusb: debug [init_device] (bus: 2, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\7&2452366F&0&0'
[ 0.042795] [000043c8] libusb: debug [winusb_get_device_list] extra GUID: {209D0288-9C4C-5B63-3A38-9EBE14E03F48}
[ 0.042904] [000043c8] libusb: debug [winusb_get_device_list] found existing device for session [1E]
[ 0.043085] [000043c8] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.043169] [000043c8] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 44 bytes)
[ 0.043278] [000043c8] libusb: debug [init_device] (bus: 1, addr: 37, depth: 1, port: 17): 'USB\VID_04B4&PID_00F0\5&E9F3E45&0&17'
[ 0.043843] [000043c8] libusb: debug [winusb_get_device_list] found existing device for session [72]
[ 0.044097] [000043c8] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.044193] [000043c8] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 1112 bytes)
[ 0.044307] [000043c8] libusb: debug [init_device] (bus: 1, addr: 4, depth: 1, port: 11): 'USB\VID_0BDA&PID_58FD\200901010001'
[ 0.044870] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL01\7&290AACAE&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.045027] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.045104] [000043c8] libusb: debug [set_composite_interface] interface[1] = \\?\HID#VID_046D&PID_C534&MI_01&COL01#7&383A3A17&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.045224] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL01\5&99B72D3&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.045371] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.045448] [000043c8] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL03\7&383A3A17&0&0002
[ 0.045573] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL03\5&379854AA&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.045720] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.045796] [000043c8] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL02\7&383A3A17&0&0001
[ 0.045896] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.045969] [000043c8] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL04\7&383A3A17&0&0003
[ 0.046074] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL01\3&36A7043C&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.046223] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL02\7&290AACAE&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.046355] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.046468] [000043c8] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL05\7&383A3A17&0&0004
[ 0.046606] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL02\3&36A7043C&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.046741] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL02\5&99B72D3&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.046868] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.046943] [000043c8] libusb: debug [set_composite_interface] interface[3] = \\?\HID#VID_047F&PID_C056&MI_03&COL01#F&39E6F119&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.047061] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL02\5&379854AA&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.047183] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.047257] [000043c8] libusb: debug [set_composite_interface] interface[3] already set - ignoring HID collection: HID\VID_047F&PID_C056&MI_03&COL02\F&39E6F119&0&0001
[ 0.047356] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.047429] [000043c8] libusb: debug [set_composite_interface] interface[3] already set - ignoring HID collection: HID\VID_047F&PID_C056&MI_03&COL03\F&39E6F119&0&0002
[ 0.047545] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL03\5&99B72D3&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.047672] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.047746] [000043c8] libusb: debug [set_composite_interface] interface[0] = \\?\HID#VID_046D&PID_C534&MI_00#7&1C54B96&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}\KBD
[ 0.047858] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL04\5&99B72D3&0&0003' (non USB HID, newly connected, etc.) - ignoring
[ 0.047999] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL05\5&99B72D3&0&0004' (non USB HID, newly connected, etc.) - ignoring
[ 0.048111] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL01\5&379854AA&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.049150] [000043c8] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.049235] [000043c8] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.050044] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.050134] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.050242] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.050324] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.050467] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.050547] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.050628] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x25
[ 0.050712] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x25
[ 0.050790] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.050870] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.050917] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.050989] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.051040] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.051113] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.051165] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.051210] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.051281] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.051333] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.051379] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.051426] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.051496] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.051545] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.5
[ 0.051592] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.30
[ 0.051638] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.051685] [000043c8] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.051732] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.051811] [000043c8] libusb: debug [libusb_open] open 1.37
[ 0.051903] [000043c8] libusb: debug [libusb_claim_interface] interface 0
[ 0.052029] [000043c8] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.052079] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.052124] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.052169] [000043c8] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 01 to interface 0
[ 0.052217] [000043c8] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.052390] [000043c8] libusb: debug [libusb_submit_transfer] transfer 000001556EB50E08
[ 0.052442] [000043c8] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 01 with interface 0
[ 0.052490] [000043c8] libusb: debug [winusbx_submit_bulk_transfer] writing 100 bytes
[ 0.052564] [000043c8] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.052611] [000043c8] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.052660] [000043c8] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.052630] [0000097c] libusb: debug [windows_iocp_thread] transfer 000001556EB50E08 completed, length 100
[ 0.052856] [000043c8] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.052903] [000043c8] libusb: debug [handle_event_trigger] event triggered
[ 0.052949] [000043c8] libusb: debug [windows_handle_transfer_completion] handling transfer 000001556EB50E08 completion with errcode 0, length 100
[ 0.053021] [000043c8] libusb: debug [usbi_handle_transfer_completion] transfer 000001556EB50E08 has callback 00007FFABB3A9220
[ 0.053090] [000043c8] libusb: debug [sync_transfer_cb] actual_length=100
[ 0.053137] [000043c8] libusb: debug [libusb_free_transfer] transfer 000001556EB50E08
[ 0.053193] [000043c8] libusb: debug [libusb_release_interface] interface 0
Number of bytes written: 100
[ 0.053320] [000043c8] libusb: debug [libusb_close]
write: True
[ 0.055705] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.37
[ 0.055832] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.0
[ 0.055960] [000043c8] libusb: debug [libusb_get_device_list]
[ 0.075353] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [93]
[ 0.075614] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [94]
[ 0.075997] [000043c8] libusb: debug [get_api_type] driver(s): BTHUSB
[ 0.076167] [000043c8] libusb: debug [get_api_type] lower filter driver(s): ibtusb
[ 0.076270] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [10]
[ 0.076568] [000043c8] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.076703] [000043c8] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.076801] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [1E]
[ 0.077285] [000043c8] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.077420] [000043c8] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.077521] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [71]
[ 0.077768] [000043c8] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.077898] [000043c8] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.077997] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [72]
[ 0.078240] [000043c8] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.078375] [000043c8] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.078473] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [73]
[ 0.078728] [000043c8] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.078858] [000043c8] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.078955] [000043c8] libusb: debug [winusb_get_device_list] allocating new device for session [74]
[ 0.079241] [000043c8] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_A36D&SUBSYS_091A1028&REV_10\3&11583659&0&A0' bus number 1
[ 0.079402] [000043c8] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_15DB&SUBSYS_091A1028&REV_02\71D9F51854B3020000' bus number 2
[ 0.081033] [000043c8] libusb: debug [winusb_get_device_list] extra GUID: {865C4DDE-10B6-6373-FAEE-1506B321A619}
[ 0.081152] [000043c8] libusb: debug [winusb_get_device_list] found existing device for session [71]
[ 0.081377] [000043c8] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.081493] [000043c8] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 59 bytes)
[ 0.081649] [000043c8] libusb: debug [init_device] (bus: 1, addr: 3, depth: 1, port: 3): 'USB\VID_046D&PID_C534\5&E9F3E45&0&3'
[ 0.081893] [000043c8] libusb: debug [winusb_get_device_list] found existing device for session [10]
[ 0.082090] [000043c8] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.082202] [000043c8] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 200 bytes)
[ 0.082354] [000043c8] libusb: debug [init_device] (bus: 1, addr: 5, depth: 1, port: 14): 'USB\VID_8087&PID_0AAA\5&E9F3E45&0&14'
[ 0.082824] [000043c8] libusb: debug [winusb_get_device_list] found existing device for session [74]
[ 0.083014] [000043c8] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.083127] [000043c8] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 288 bytes)
[ 0.083249] [000043c8] libusb: debug [init_device] (bus: 1, addr: 30, depth: 1, port: 2): 'USB\VID_047F&PID_C056\D1CEC32927974D5F9BD6B2AEBF2EA8E3'
[ 0.083694] [000043c8] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\4&36020D6F&0&0' reports 26 ports
[ 0.083870] [000043c8] libusb: debug [init_device] (bus: 1, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\4&36020D6F&0&0'
[ 0.084059] [000043c8] libusb: debug [winusb_get_device_list] found existing device for session [73]
[ 0.084219] [000043c8] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.084305] [000043c8] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 269 bytes)
[ 0.084416] [000043c8] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 10): 'USB\VID_0A5C&PID_5842\0123456789ABCD'
[ 0.084868] [000043c8] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\7&2452366F&0&0' reports 4 ports
[ 0.084978] [000043c8] libusb: debug [init_device] (bus: 2, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\7&2452366F&0&0'
[ 0.085293] [000043c8] libusb: debug [winusb_get_device_list] extra GUID: {209D0288-9C4C-5B63-3A38-9EBE14E03F48}
[ 0.085377] [000043c8] libusb: debug [winusb_get_device_list] found existing device for session [1E]
[ 0.085554] [000043c8] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.085636] [000043c8] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 44 bytes)
[ 0.085752] [000043c8] libusb: debug [init_device] (bus: 1, addr: 37, depth: 1, port: 17): 'USB\VID_04B4&PID_00F0\5&E9F3E45&0&17'
[ 0.086284] [000043c8] libusb: debug [winusb_get_device_list] found existing device for session [72]
[ 0.086450] [000043c8] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.086536] [000043c8] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 1112 bytes)
[ 0.086649] [000043c8] libusb: debug [init_device] (bus: 1, addr: 4, depth: 1, port: 11): 'USB\VID_0BDA&PID_58FD\200901010001'
[ 0.087042] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL01\7&290AACAE&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.087171] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.087245] [000043c8] libusb: debug [set_composite_interface] interface[1] = \\?\HID#VID_046D&PID_C534&MI_01&COL01#7&383A3A17&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.087359] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL01\5&99B72D3&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.087500] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.087627] [000043c8] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL03\7&383A3A17&0&0002
[ 0.087800] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL03\5&379854AA&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.087955] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.088045] [000043c8] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL02\7&383A3A17&0&0001
[ 0.088193] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.088253] [000043c8] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL04\7&383A3A17&0&0003
[ 0.088425] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL01\3&36A7043C&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.088580] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL02\7&290AACAE&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.088749] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.088852] [000043c8] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL05\7&383A3A17&0&0004
[ 0.089006] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL02\3&36A7043C&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.089137] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL02\5&99B72D3&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.089295] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.089388] [000043c8] libusb: debug [set_composite_interface] interface[3] = \\?\HID#VID_047F&PID_C056&MI_03&COL01#F&39E6F119&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.089548] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL02\5&379854AA&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.089696] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.089787] [000043c8] libusb: debug [set_composite_interface] interface[3] already set - ignoring HID collection: HID\VID_047F&PID_C056&MI_03&COL02\F&39E6F119&0&0001
[ 0.089934] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.090022] [000043c8] libusb: debug [set_composite_interface] interface[3] already set - ignoring HID collection: HID\VID_047F&PID_C056&MI_03&COL03\F&39E6F119&0&0002
[ 0.090213] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL03\5&99B72D3&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.090365] [000043c8] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.090455] [000043c8] libusb: debug [set_composite_interface] interface[0] = \\?\HID#VID_046D&PID_C534&MI_00#7&1C54B96&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}\KBD
[ 0.090618] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL04\5&99B72D3&0&0003' (non USB HID, newly connected, etc.) - ignoring
[ 0.090779] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL05\5&99B72D3&0&0004' (non USB HID, newly connected, etc.) - ignoring
[ 0.090922] [000043c8] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL01\5&379854AA&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.092017] [000043c8] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.092145] [000043c8] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.092988] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.093066] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.093149] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.093203] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.093292] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.093348] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.093394] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x25
[ 0.093440] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x25
[ 0.093513] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.093564] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.093612] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.093681] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.093733] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.093805] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.093855] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.093902] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.093969] [000043c8] libusb: debug [libusb_get_device_descriptor]
[ 0.094019] [000043c8] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.094065] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.094109] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.094178] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.094227] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.5
[ 0.094272] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.30
[ 0.094318] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.094364] [000043c8] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.094407] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.094507] [000043c8] libusb: debug [libusb_open] open 1.37
[ 0.094600] [000043c8] libusb: debug [libusb_claim_interface] interface 0
[ 0.094719] [000043c8] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.094769] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.094813] [000043c8] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.094857] [000043c8] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 01 to interface 0
[ 0.094904] [000043c8] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.095073] [000043c8] libusb: debug [libusb_submit_transfer] transfer 000001556EB50E08
[ 0.095123] [000043c8] libusb: debug [add_to_flying_list] arm timer for timeout in 10ms (first in line)
[ 0.095179] [000043c8] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 81 with interface 0
[ 0.095225] [000043c8] libusb: debug [winusbx_submit_bulk_transfer] reading 1024 bytes
[ 0.095308] [000043c8] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.095358] [000043c8] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.095390] [0000097c] libusb: debug [windows_iocp_thread] transfer 000001556EB50E08 completed, length 100
[ 0.095566] [000043c8] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.095616] [000043c8] libusb: debug [handle_event_trigger] event triggered
[ 0.095660] [000043c8] libusb: debug [windows_handle_transfer_completion] handling transfer 000001556EB50E08 completion with errcode 0, length 100
[ 0.095730] [000043c8] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.095774] [000043c8] libusb: debug [usbi_handle_transfer_completion] transfer 000001556EB50E08 has callback 00007FFABB3A9220
[ 0.095841] [000043c8] libusb: debug [sync_transfer_cb] actual_length=100
[ 0.095887] [000043c8] libusb: debug [libusb_free_transfer] transfer 000001556EB50E08
[ 0.095956] [000043c8] libusb: debug [libusb_submit_transfer] transfer 000001556EB50E08
[ 0.096003] [000043c8] libusb: debug [add_to_flying_list] arm timer for timeout in 10ms (first in line)
[ 0.096050] [000043c8] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 81 with interface 0
[ 0.096094] [000043c8] libusb: debug [winusbx_submit_bulk_transfer] reading 1024 bytes
[ 0.096154] [000043c8] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.096202] [000043c8] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.119260] [000043c8] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 1
[ 0.119475] [000043c8] libusb: debug [libusb_cancel_transfer] transfer 000001556EB50E08
[ 0.119620] [000043c8] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.119735] [000043c8] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.119829] [000043c8] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.119774] [0000097c] libusb: debug [windows_iocp_thread] transfer 000001556EB50E08 completed, length 0
[ 0.120206] [000043c8] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.120340] [000043c8] libusb: debug [handle_event_trigger] event triggered
[ 0.120480] [000043c8] libusb: debug [windows_handle_transfer_completion] handling transfer 000001556EB50E08 completion with errcode 995, length 0
[ 0.120654] [000043c8] libusb: debug [windows_handle_transfer_completion] detected operation aborted
[ 0.120791] [000043c8] libusb: debug [usbi_handle_transfer_cancellation] detected timeout cancellation
[ 0.120946] [000043c8] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.121086] [000043c8] libusb: debug [usbi_handle_transfer_completion] transfer 000001556EB50E08 has callback 00007FFABB3A9220
[ 0.121249] [000043c8] libusb: debug [sync_transfer_cb] actual_length=0
[ 0.121358] [000043c8] libusb: debug [libusb_free_transfer] transfer 000001556EB50E08
[ 0.121517] [000043c8] libusb: debug [libusb_release_interface] interface 0
[ 0.121640] [000043c8] libusb: debug [libusb_close]
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
[ 0.125511] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.37
[ 0.125672] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.0
Closing USB
[ 0.125944] [000043c8] libusb: debug [libusb_exit]
[ 0.126109] [0000097c] libusb: debug [windows_iocp_thread] I/O completion thread exiting
[ 0.127922] [000043c8] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000648
[ 0.128040] [000043c8] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000644
Close handle successfully
Calling closing method to delete self
Closing USB
Close handle successfully
from python-libusb1.
[ 0.053320] [000043c8] libusb: debug [libusb_close]
write: True
[ 0.055705] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.37
[ 0.055832] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.0
[...]
[ 0.121640] [000043c8] libusb: debug [libusb_close]
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
[ 0.125511] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.37
[ 0.125672] [000043c8] libusb: debug [libusb_unref_device] destroy device 1.0
Closing USB
Excellent. And device 1.0 appears too, which I was not sure about. Here I feel we have touched the bottom of this issue.
I think I have found a cleaner way to fix this issue than explicit gc calls. I pushed the fix in a temporary branch, could you try this (at least without the gc.collect()
s, and ideally with the code you originally triggered the issue with) ?
from python-libusb1.
The wip branch seems to help but there are a lot of warnings. And I think it still has some issues. Main issue is that the bahavior is not so consistent and sometimes the app will hang. And often there is this "usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]" error message.
Code:
# codes from https://github.com/vpelletier/python-libusb1/issues/72
import usb1
class USB:
"""USB class that handles IO operation with USB device
ENDPOINT_IN: device-to-host, ENDPOINT_OUT: host-to-device"""
# read size chunk
READ_CHUNK = 1024
def __init__(self, pid: hex, vid: hex, endpoint_in: hex, endpoint_out: hex) -> None:
self.endpoint_in = endpoint_in
self.endpoint_out = endpoint_out
self.pid = pid
self.vid = vid
self.context = usb1.USBContext()
def is_connected(self) -> bool:
"""Check if specified device is connected"""
with usb1.USBContext() as context:
for device in context.getDeviceIterator(skip_on_error=True):
if device.getVendorID() == self.vid and device.getProductID() == self.pid:
return True
def open(self) -> bool:
"""Open USB and initialize interface"""
try:
self.context.open()
return True
except Exception as err:
print("open device error:", err)
return False
def __get_handle(self):
"""return handle object"""
return self.context.openByVendorIDAndProductID(self.vid, self.pid)
def close(self) -> bool:
"""Close USB"""
print("Closing USB")
try:
self.context.close()
print("Close handle successfully")
return True
except Exception as err:
print("Close handle error:", err)
return False
def write(self, msg: bytearray, timeout: int = 0) -> bool:
"""write an specific msg to device"""
handle = self.__get_handle()
if not handle:
return False
try:
with handle.claimInterface(0):
bytes_written = handle.bulkWrite(
self.endpoint_out, msg, timeout)
bytes_written == len(msg)
print("Number of bytes written: ", bytes_written)
return True
except Exception as err:
print("write error", err)
#handle.close()
return False
def read(self, timeout: int = 10) -> bytearray:
"""read data from the device"""
data = bytearray()
handle = self.__get_handle()
if not handle:
return False
try:
with handle.claimInterface(0):
while True:
try:
data += handle.bulkRead(self.endpoint_in,
self.READ_CHUNK, timeout)
except usb1.USBErrorTimeout:
break
except Exception as err:
print("read error", err)
return None
handle.close()
return data
def __del__(self):
print("Calling closing method to delete self")
self.close()
if __name__ == '__main__':
VENDOR_ID = 0x04b4
PRODUCT_ID = 0x00f0
ENDPOINT_IN = 0x81
ENDPOINT_OUT = 0x01
usb = USB(PRODUCT_ID, VENDOR_ID, ENDPOINT_IN, ENDPOINT_OUT)
#print(usb.is_connected())
msg = 100 * bytearray(b"B")
if usb.open():
print("write:", usb.write(msg))
print("read:", usb.read())
# error after adding this line
usb.close()
Before the change (using release 1.9.3 version):
(py39venv) C:\work\libusb\python-libusb1_wip [wip ≡]> python ..\python_usb\cyusb_fx3_bulkloop_python_libusb1.py
Number of bytes written: 100
write: True
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
Closing USB
Close handle successfully
Exception ignored in: <function USBDevice.__del__ at 0x0000022811E0B940>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1778, in __del__
self.close()
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1790, in close
self.__libusb_unref_device(self.device_p)
OSError: exception: access violation writing 0x0000000000000024
Calling closing method to delete self
Closing USB
Close handle successfully
After:
(py39venv) C:\work\libusb\python-libusb1_wip [wip ≡]> pip install .
Processing c:\work\libusb\python-libusb1_wip
DEPRECATION: A future pip version will change local packages to be built in-place without first copying to a temporary directory. We recommend you use --use-feature=in-tree-build to test your packages with this new behavior before it becomes the default.
pip 21.3 will remove support for this functionality. You can find discussion regarding this at https://github.com/pypa/pip/issues/7555.
Building wheels for collected packages: libusb1
Building wheel for libusb1 (setup.py) ... done
Created wheel for libusb1: filename=libusb1-1.9.3+4.gd88e2c0-py3-none-any.whl size=61334 sha256=e73a9f33af3b5da78cf58867e0232b5b45a88b31f7e9e20c3b6e8fd619f31cc5
Stored in directory: c:\users\xfchen\appdata\local\pip\cache\wheels\bf\01\cd\b543f3d47446fe65650c507543ffbc55d31914858eea76b1f1
Successfully built libusb1
Installing collected packages: libusb1
Attempting uninstall: libusb1
Found existing installation: libusb1 1.9.3
Uninstalling libusb1-1.9.3:
Successfully uninstalled libusb1-1.9.3
Successfully installed libusb1-1.9.3+4.gd88e2c0
(py39venv) C:\work\libusb\python-libusb1_wip [wip ≡]> $Env:LIBUSB_DEBUG=4
(py39venv) C:\work\libusb\python-libusb1_wip [wip ≡]> python ..\python_usb\cyusb_fx3_bulkloop_python_libusb1.py
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000271] [00001128] libusb: debug [libusb_init] libusb v1.0.24.11650
[ 0.000386] [00001128] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000608 events 0
[ 0.000600] [00001128] libusb: debug [usbi_io_init] using timer for timeouts
[ 0.000689] [00001128] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000680 events 0
[ 0.000782] [00001128] libusb: debug [get_windows_version] Windows 10 64-bit
[ 0.000890] [00001128] libusb: debug [htab_create] using 1021 entries hash table
[ 0.003879] [00001128] libusb: info [winusbx_init] WinUSB DLL available (with isoch support)
[ 0.004970] [00001128] libusb: debug [winusbx_init] libusbK DLL found, version: 3.1.0.0
[ 0.010338] [00001128] libusb: debug [windows_init] UsbDk backend is available
[ 0.010652] [00001128] libusb: debug [libusb_get_device_list]
[ 0.011915] [00000e50] libusb: debug [windows_iocp_thread] I/O completion thread started
[ 0.031572] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [94]
[ 0.031808] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [95]
[ 0.032245] [00001128] libusb: debug [get_api_type] driver(s): BTHUSB
[ 0.032419] [00001128] libusb: debug [get_api_type] lower filter driver(s): ibtusb
[ 0.032527] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [10]
[ 0.032816] [00001128] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.032951] [00001128] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.033053] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [1E]
[ 0.033528] [00001128] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.033664] [00001128] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.033761] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [71]
[ 0.034021] [00001128] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.034152] [00001128] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.034248] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [72]
[ 0.034490] [00001128] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.034620] [00001128] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.034720] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [73]
[ 0.035058] [00001128] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.035210] [00001128] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.035312] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [74]
[ 0.035616] [00001128] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_A36D&SUBSYS_091A1028&REV_10\3&11583659&0&A0' bus number 1
[ 0.035853] [00001128] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_15DB&SUBSYS_091A1028&REV_02\71D9F51854B3020000' bus number 2
[ 0.037821] [00001128] libusb: debug [winusb_get_device_list] extra GUID: {865C4DDE-10B6-6373-FAEE-1506B321A619}
[ 0.037962] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [71]
[ 0.038236] [00001128] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.038362] [00001128] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 59 bytes)
[ 0.038513] [00001128] libusb: debug [init_device] (bus: 1, addr: 3, depth: 1, port: 3): 'USB\VID_046D&PID_C534\5&E9F3E45&0&3'
[ 0.038775] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [10]
[ 0.038978] [00001128] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.039091] [00001128] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 200 bytes)
[ 0.039245] [00001128] libusb: debug [init_device] (bus: 1, addr: 6, depth: 1, port: 14): 'USB\VID_8087&PID_0AAA\5&E9F3E45&0&14'
[ 0.039717] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [74]
[ 0.039910] [00001128] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.039974] [00001128] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 288 bytes)
[ 0.040121] [00001128] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 2): 'USB\VID_047F&PID_C056\D1CEC32927974D5F9BD6B2AEBF2EA8E3'
[ 0.040600] [00001128] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\4&36020D6F&0&0' reports 26 ports
[ 0.040781] [00001128] libusb: debug [init_device] (bus: 1, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\4&36020D6F&0&0'
[ 0.040980] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [73]
[ 0.041155] [00001128] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.041243] [00001128] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 269 bytes)
[ 0.041357] [00001128] libusb: debug [init_device] (bus: 1, addr: 4, depth: 1, port: 10): 'USB\VID_0A5C&PID_5842\0123456789ABCD'
[ 0.041830] [00001128] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\7&2452366F&0&0' reports 4 ports
[ 0.041938] [00001128] libusb: debug [init_device] (bus: 2, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\7&2452366F&0&0'
[ 0.042260] [00001128] libusb: debug [winusb_get_device_list] extra GUID: {209D0288-9C4C-5B63-3A38-9EBE14E03F48}
[ 0.042346] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [1E]
[ 0.042516] [00001128] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.042601] [00001128] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 44 bytes)
[ 0.042715] [00001128] libusb: debug [init_device] (bus: 1, addr: 16, depth: 1, port: 17): 'USB\VID_04B4&PID_00F0\5&E9F3E45&0&17'
[ 0.043248] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [72]
[ 0.043416] [00001128] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.043503] [00001128] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 1112 bytes)
[ 0.043618] [00001128] libusb: debug [init_device] (bus: 1, addr: 5, depth: 1, port: 11): 'USB\VID_0BDA&PID_58FD\200901010001'
[ 0.044053] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL01\7&290AACAE&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.044183] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.044262] [00001128] libusb: debug [set_composite_interface] interface[1] = \\?\HID#VID_046D&PID_C534&MI_01&COL01#7&383A3A17&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.044409] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL01\5&99B72D3&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.044549] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.044621] [00001128] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL03\7&383A3A17&0&0002
[ 0.044735] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL03\5&379854AA&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.044833] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.044879] [00001128] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL02\7&383A3A17&0&0001
[ 0.045038] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.045108] [00001128] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL04\7&383A3A17&0&0003
[ 0.045267] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL01\3&36A7043C&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.045411] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL02\7&290AACAE&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.045516] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.045562] [00001128] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL05\7&383A3A17&0&0004
[ 0.045660] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL02\3&36A7043C&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.045763] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL02\5&99B72D3&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.045856] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.045901] [00001128] libusb: debug [set_composite_interface] interface[3] = \\?\HID#VID_047F&PID_C056&MI_03&COL01#F&39E6F119&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.046019] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL02\5&379854AA&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.046113] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.046157] [00001128] libusb: debug [set_composite_interface] interface[3] already set - ignoring HID collection: HID\VID_047F&PID_C056&MI_03&COL02\F&39E6F119&0&0001
[ 0.046249] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.046295] [00001128] libusb: debug [set_composite_interface] interface[3] already set - ignoring HID collection: HID\VID_047F&PID_C056&MI_03&COL03\F&39E6F119&0&0002
[ 0.046395] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL03\5&99B72D3&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.046490] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.046536] [00001128] libusb: debug [set_composite_interface] interface[0] = \\?\HID#VID_046D&PID_C534&MI_00#7&1C54B96&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}\KBD
[ 0.046637] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL04\5&99B72D3&0&0003' (non USB HID, newly connected, etc.) - ignoring
[ 0.046739] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL05\5&99B72D3&0&0004' (non USB HID, newly connected, etc.) - ignoring
[ 0.046925] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL01\5&379854AA&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.048052] [00001128] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.048241] [00001128] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.049134] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.049221] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.049331] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.049385] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x00000256A930B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
[ 0.052363] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.052489] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.052548] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x25
[ 0.052601] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x25
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x00000256A930B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
[ 0.055215] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.055289] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.055337] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x30
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x00000256A930B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
[ 0.057850] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.057918] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x00000256A930B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
[ 0.060381] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.060437] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.060484] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x30
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x00000256A930B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
[ 0.063124] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.063183] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.063230] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.063275] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x30
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x00000256A930B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
[ 0.065596] [00001128] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.065648] [00001128] libusb: debug [libusb_unref_device] destroy device 1.6
[ 0.065693] [00001128] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.065740] [00001128] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.065785] [00001128] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.065828] [00001128] libusb: debug [libusb_unref_device] destroy device 1.5
[ 0.065914] [00001128] libusb: debug [libusb_open] open 1.16
[ 0.066010] [00001128] libusb: debug [libusb_claim_interface] interface 0
[ 0.066143] [00001128] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.066192] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.066235] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.066280] [00001128] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 01 to interface 0
[ 0.066326] [00001128] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.066496] [00001128] libusb: debug [libusb_submit_transfer] transfer 00000256A89FCF08
[ 0.066547] [00001128] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 01 with interface 0
[ 0.066592] [00001128] libusb: debug [winusbx_submit_bulk_transfer] writing 100 bytes
[ 0.066662] [00001128] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.066710] [00001128] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.066757] [00001128] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.066730] [00000e50] libusb: debug [windows_iocp_thread] transfer 00000256A89FCF08 completed, length 100
[ 0.066964] [00001128] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.067010] [00001128] libusb: debug [handle_event_trigger] event triggered
[ 0.067052] [00001128] libusb: debug [windows_handle_transfer_completion] handling transfer 00000256A89FCF08 completion with errcode 0, length 100
[ 0.067122] [00001128] libusb: debug [usbi_handle_transfer_completion] transfer 00000256A89FCF08 has callback 00007FF9CBBE9220
[ 0.067188] [00001128] libusb: debug [sync_transfer_cb] actual_length=100
[ 0.067267] [00001128] libusb: debug [libusb_free_transfer] transfer 00000256A89FCF08
[ 0.067380] [00001128] libusb: debug [libusb_release_interface] interface 0
Number of bytes written: 100
write: True
[ 0.067738] [00001128] libusb: debug [libusb_get_device_list]
[ 0.086850] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [94]
[ 0.087068] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [95]
[ 0.087457] [00001128] libusb: debug [get_api_type] driver(s): BTHUSB
[ 0.087622] [00001128] libusb: debug [get_api_type] lower filter driver(s): ibtusb
[ 0.087729] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [10]
[ 0.088022] [00001128] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.088195] [00001128] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.088354] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [1E]
[ 0.088900] [00001128] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.089038] [00001128] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.089135] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [71]
[ 0.089386] [00001128] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.089517] [00001128] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.089617] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [72]
[ 0.089862] [00001128] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.089994] [00001128] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.090099] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [73]
[ 0.090416] [00001128] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.090547] [00001128] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.090624] [00001128] libusb: debug [winusb_get_device_list] allocating new device for session [74]
[ 0.090941] [00001128] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_15DB&SUBSYS_091A1028&REV_02\71D9F51854B3020000' bus number 2
[ 0.092630] [00001128] libusb: debug [winusb_get_device_list] extra GUID: {865C4DDE-10B6-6373-FAEE-1506B321A619}
[ 0.092737] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [71]
[ 0.092903] [00001128] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.092988] [00001128] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 59 bytes)
[ 0.093103] [00001128] libusb: debug [init_device] (bus: 1, addr: 3, depth: 1, port: 3): 'USB\VID_046D&PID_C534\5&E9F3E45&0&3'
[ 0.093319] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [10]
[ 0.093485] [00001128] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.093566] [00001128] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 200 bytes)
[ 0.093674] [00001128] libusb: debug [init_device] (bus: 1, addr: 6, depth: 1, port: 14): 'USB\VID_8087&PID_0AAA\5&E9F3E45&0&14'
[ 0.094077] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [74]
[ 0.094241] [00001128] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.094322] [00001128] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 288 bytes)
[ 0.094424] [00001128] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 2): 'USB\VID_047F&PID_C056\D1CEC32927974D5F9BD6B2AEBF2EA8E3'
[ 0.094955] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [73]
[ 0.095150] [00001128] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.095259] [00001128] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 269 bytes)
[ 0.095410] [00001128] libusb: debug [init_device] (bus: 1, addr: 4, depth: 1, port: 10): 'USB\VID_0A5C&PID_5842\0123456789ABCD'
[ 0.095915] [00001128] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\7&2452366F&0&0' reports 4 ports
[ 0.096047] [00001128] libusb: debug [init_device] (bus: 2, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\7&2452366F&0&0'
[ 0.096376] [00001128] libusb: debug [winusb_get_device_list] extra GUID: {209D0288-9C4C-5B63-3A38-9EBE14E03F48}
[ 0.096467] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [1E]
[ 0.097055] [00001128] libusb: debug [winusb_get_device_list] found existing device for session [72]
[ 0.097228] [00001128] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.097320] [00001128] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 1112 bytes)
[ 0.097431] [00001128] libusb: debug [init_device] (bus: 1, addr: 5, depth: 1, port: 11): 'USB\VID_0BDA&PID_58FD\200901010001'
[ 0.097843] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL01\7&290AACAE&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.097975] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.098093] [00001128] libusb: debug [set_composite_interface] interface[1] = \\?\HID#VID_046D&PID_C534&MI_01&COL01#7&383A3A17&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.098240] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL01\5&99B72D3&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.098416] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.098515] [00001128] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL03\7&383A3A17&0&0002
[ 0.098646] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL03\5&379854AA&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.098802] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.098898] [00001128] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL02\7&383A3A17&0&0001
[ 0.099007] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.099080] [00001128] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL04\7&383A3A17&0&0003
[ 0.099184] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL01\3&36A7043C&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.099300] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL02\7&290AACAE&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.099428] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.099501] [00001128] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL05\7&383A3A17&0&0004
[ 0.099604] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL02\3&36A7043C&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.099736] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL02\5&99B72D3&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.099858] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.099933] [00001128] libusb: debug [set_composite_interface] interface[3] = \\?\HID#VID_047F&PID_C056&MI_03&COL01#F&39E6F119&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.100076] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL02\5&379854AA&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.100190] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.100237] [00001128] libusb: debug [set_composite_interface] interface[3] already set - ignoring HID collection: HID\VID_047F&PID_C056&MI_03&COL02\F&39E6F119&0&0001
[ 0.100336] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [74]:
[ 0.100383] [00001128] libusb: debug [set_composite_interface] interface[3] already set - ignoring HID collection: HID\VID_047F&PID_C056&MI_03&COL03\F&39E6F119&0&0002
[ 0.100487] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL03\5&99B72D3&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.100630] [00001128] libusb: debug [winusb_get_device_list] setting composite interface for [71]:
[ 0.100730] [00001128] libusb: debug [set_composite_interface] interface[0] = \\?\HID#VID_046D&PID_C534&MI_00#7&1C54B96&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}\KBD
[ 0.100887] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL04\5&99B72D3&0&0003' (non USB HID, newly connected, etc.) - ignoring
[ 0.101041] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL05\5&99B72D3&0&0004' (non USB HID, newly connected, etc.) - ignoring
[ 0.101202] [00001128] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL01\5&379854AA&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.102328] [00001128] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.102450] [00001128] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.103250] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.103315] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.103430] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.103484] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x00000256A930B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
[ 0.106059] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.106116] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.106162] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x25
[ 0.106209] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x25
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x00000256A930B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
[ 0.108789] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.108847] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.108894] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x30
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x00000256A930B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
[ 0.111352] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.111467] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x00000256A930B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
[ 0.114205] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.114313] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.114416] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x30
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x00000256A930B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
[ 0.116859] [00001128] libusb: debug [libusb_get_device_descriptor]
[ 0.116919] [00001128] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.116965] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.117010] [00001128] libusb: debug [parse_endpoint] skipping descriptor 0x30
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x00000256A930B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
[ 0.119648] [00001128] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.119704] [00001128] libusb: debug [libusb_unref_device] destroy device 1.6
[ 0.119749] [00001128] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.119795] [00001128] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.119840] [00001128] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.119883] [00001128] libusb: debug [libusb_unref_device] destroy device 1.5
[ 0.119962] [00001128] libusb: debug [libusb_open] open 1.16
[ 0.120037] [00001128] libusb: error [winusbx_open] could not open device \\?\USB#VID_04B4&PID_00F0#5&E9F3E45&0&17#{A5DCBF10-6530-11D2-901F-00C04FB951ED} (interface 0): [5] Access is denied.
[ 0.120114] [00001128] libusb: debug [libusb_open] open 1.16 returns -3
Traceback (most recent call last):
File "C:\work\libusb\python_usb\cyusb_fx3_bulkloop_python_libusb1.py", line 102, in <module>
print("read:", usb.read())
File "C:\work\libusb\python_usb\cyusb_fx3_bulkloop_python_libusb1.py", line 70, in read
handle = self.__get_handle()
File "C:\work\libusb\python_usb\cyusb_fx3_bulkloop_python_libusb1.py", line 36, in __get_handle
return self.context.openByVendorIDAndProductID(self.vid, self.pid)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2325, in openByVendorIDAndProductID
return result.open()
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2082, in open
mayRaiseUSBError(libusb1.libusb_open(self.device_p, byref(handle)))
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 127, in mayRaiseUSBError
__raiseUSBError(value)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 119, in raiseUSBError
raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x00000256A930B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
[ 0.132021] [00001128] libusb: debug [libusb_close]
[ 0.132232] [00001128] libusb: debug [libusb_unref_device] destroy device 1.16
Calling closing method to delete self
Closing USB
[ 0.134420] [00001128] libusb: debug [libusb_exit]
[ 0.134577] [00000e50] libusb: debug [windows_iocp_thread] I/O completion thread exiting
[ 0.136633] [00001128] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000680
[ 0.136756] [00001128] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000608
[ 0.136870] [00001128] libusb: warning [libusb_exit] device 1.0 still referenced
Close handle successfully
from python-libusb1.
In the case of hang:
(py39venv) C:\work\libusb\python-libusb1_wip [wip ≡]> python ..\python_usb\cyusb_fx3_bulkloop_python_libusb1.py
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x0000020531B1C5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x0000020531B1C5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x0000020531B1C5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x0000020531B1C5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x0000020531B1C5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x0000020531B1C5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2163, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x.close())
AttributeError: 'weakref' object has no attribute 'close'
... hang here and I have to hit reset of the device to recover ...
KeyboardInterrupt
Calling closing method to delete self
Closing USB
Close handle successfully
Exception ignored in: <function USBDeviceHandle.__del__ at 0x0000020531AF8670>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1077, in __del__
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1122, in close
OSError: exception: access violation writing 0x0000000000000024
from python-libusb1.
BTW, I am not sure if this has anything to do with the topic here: rene-aguirre/pywinusb#56 .
The issue is not related to libusb (pywinusb is only for HID device despite the name. It is Windows only). Interestingly, the pywinusb issue goes away with Python 3.9. So the issue is not exactly the same. Nevertheless it seems to me Windows Python is a bit different from other platforms.
from python-libusb1.
AttributeError: 'weakref' object has no attribute 'close'
Woops, I did not notice it would receive the weakref and not the referent. I fixed this and pushed to wip branch.
But I also found something else in the weakref documentation which may make this solution impossible. If you get similar errors but with NoneType
instead of weakref
in the error, then this is not going to work and I have to find yet another way.
from python-libusb1.
BTW, I am not sure if this has anything to do with the topic here: rene-aguirre/pywinusb#56 .
I am wary about making conclusions when there is another issue already going on (the weakref callback raising). Garbage collection is a very ticklish beast, small changes can make a large impact. Adding or removing __del__
methods can change the order in which objects get collected, and IIRC prevents python from breaking reference cycles. I started python-libusb1 before knowing this, and now getting rid of these __del__
requires more thinking. I am hoping that my pending change could make this easier... Except if it just does not work.
from python-libusb1.
But I also found something else in the weakref documentation which may make this solution impossible. If you get similar errors but with
NoneType
instead ofweakref
in the error, then this is not going to work and I have to find yet another way.
Unfortunately this seems to be the case.
(py39venv) C:\work\libusb\python-libusb1-wip [wip ≡]> python ..\python_usb\cyusb_fx3_bulkloop_python_libusb1.py
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x000002332FD0B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2164, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x().close())
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x000002332FD0B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2164, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x().close())
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x000002332FD0B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2164, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x().close())
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x000002332FD0B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2164, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x().close())
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x000002332FD0B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2164, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x().close())
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x000002332FD0B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2164, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x().close())
AttributeError: 'NoneType' object has no attribute 'close'
Number of bytes written: 100
write: True
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x000002332FD0B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2164, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x().close())
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x000002332FD0B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2164, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x().close())
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x000002332FD0B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2164, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x().close())
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x000002332FD0B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2164, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x().close())
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x000002332FD0B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2164, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x().close())
AttributeError: 'NoneType' object has no attribute 'close'
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x000002332FD0B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2164, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x().close())
AttributeError: 'NoneType' object has no attribute 'close'
Traceback (most recent call last):
File "C:\work\libusb\python_usb\cyusb_fx3_bulkloop_python_libusb1.py", line 102, in <module>
print("read:", usb.read())
File "C:\work\libusb\python_usb\cyusb_fx3_bulkloop_python_libusb1.py", line 70, in read
handle = self.__get_handle()
File "C:\work\libusb\python_usb\cyusb_fx3_bulkloop_python_libusb1.py", line 36, in __get_handle
return self.context.openByVendorIDAndProductID(self.vid, self.pid)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2326, in openByVendorIDAndProductID
return result.open()
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2083, in open
mayRaiseUSBError(libusb1.libusb_open(self.device_p, byref(handle)))
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 127, in mayRaiseUSBError
__raiseUSBError(value)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 119, in raiseUSBError
raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]
Exception ignored in: <function _WeakSetCallback.__init__.<locals>._remove at 0x000002332FD0B5E0>
Traceback (most recent call last):
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 263, in _remove
callback(item)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2164, in <lambda>
self.__close_set = _WeakSetCallback(callback=lambda x: x().close())
AttributeError: 'NoneType' object has no attribute 'close'
Calling closing method to delete self
Closing USB
Close handle successfully
from python-libusb1.
I think I have a better solution, just force-pushed in wip
branch. It turned out the be a lot more work, but it had some very nice payoffs as side-effects (almost no __del__
method left). Could you give it a try ?
from python-libusb1.
This does not seem to work.
(py39venv) C:\work\libusb\python-libusb1_wip [wip ≡]> python ..\python_usb\cyusb_fx3_bulkloop_python_libusb1.py
Traceback (most recent call last):
File "C:\work\libusb\python_usb\cyusb_fx3_bulkloop_python_libusb1.py", line 101, in <module>
print("write:", usb.write(msg))
File "C:\work\libusb\python_usb\cyusb_fx3_bulkloop_python_libusb1.py", line 51, in write
handle = self.__get_handle()
File "C:\work\libusb\python_usb\cyusb_fx3_bulkloop_python_libusb1.py", line 36, in __get_handle
return self.context.openByVendorIDAndProductID(self.vid, self.pid)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2536, in openByVendorIDAndProductID
return result.open()
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 2254, in open
return USBDeviceHandle(
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1236, in __init__
registerFinalizer(handle, self.close)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1990, in __registerFinalizer
assert handle not in self.__finalizer_dict
TypeError: unhashable type
Traceback (most recent call last):
File "C:\Python39\lib\weakref.py", line 656, in _exitfunc
f()
File "C:\Python39\lib\weakref.py", line 580, in __call__
return info.func(*info.args, **(info.kwargs or {}))
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1290, in close
unregisterFinalizer(handle)
File "C:\work\python\py39venv\lib\site-packages\usb1\__init__.py", line 1994, in __unregisterFinalizer
self.__finalizer_dict.pop(handle)
KeyError: <usb1.libusb1.LP_libusb_device_handle object at 0x0000025FBCE3E3C0>
Calling closing method to delete self
Closing USB
Close handle successfully
from python-libusb1.
TypeError: unhashable type
Woops, I had fixed one such occurrence, and forgot about the 2 others, sorry. I pushed a fix.
from python-libusb1.
Now it hangs without any errors.
debug log
(py39venv) C:\work\libusb\python-libusb1_wip [wip ≡]> $Env:LIBUSB_DEBUG=4
(py39venv) C:\work\libusb\python-libusb1_wip [wip ≡]> python ..\python_usb\cyusb_fx3_bulkloop_python_libusb1_debug.py
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000322] [00004bd4] libusb: debug [libusb_init] libusb v1.0.24.11650
[ 0.000481] [00004bd4] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000668 events 0
[ 0.000637] [00004bd4] libusb: debug [usbi_io_init] using timer for timeouts
[ 0.000724] [00004bd4] libusb: debug [usbi_add_event_source] add HANDLE 00000000000005F0 events 0
[ 0.000894] [00004bd4] libusb: debug [get_windows_version] Windows 10 64-bit
[ 0.001043] [00004bd4] libusb: debug [htab_create] using 1021 entries hash table
[ 0.003927] [00004bd4] libusb: info [winusbx_init] WinUSB DLL available (with isoch support)
[ 0.005002] [00004bd4] libusb: debug [winusbx_init] libusbK DLL found, version: 3.1.0.0
[ 0.009176] [00004bd4] libusb: error [load_usbdk_helper_dll] Failed to load UsbDkHelper.dll: [126] The specified module could not be found.
[ 0.009368] [00004bd4] libusb: info [windows_init] UsbDk backend is not available
[ 0.009854] [00004bd4] libusb: debug [libusb_get_device_list]
[ 0.010888] [00000750] libusb: debug [windows_iocp_thread] I/O completion thread started
[ 0.030638] [00004bd4] libusb: debug [winusb_get_device_list] allocating new device for session [97]
[ 0.030886] [00004bd4] libusb: debug [winusb_get_device_list] allocating new device for session [98]
[ 0.031357] [00004bd4] libusb: debug [get_api_type] driver(s): BTHUSB
[ 0.031593] [00004bd4] libusb: debug [get_api_type] lower filter driver(s): ibtusb
[ 0.031763] [00004bd4] libusb: debug [winusb_get_device_list] allocating new device for session [16]
[ 0.032176] [00004bd4] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.032374] [00004bd4] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.032480] [00004bd4] libusb: debug [winusb_get_device_list] allocating new device for session [24]
[ 0.032981] [00004bd4] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.033116] [00004bd4] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.033215] [00004bd4] libusb: debug [winusb_get_device_list] allocating new device for session [74]
[ 0.033462] [00004bd4] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.033594] [00004bd4] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.033699] [00004bd4] libusb: debug [winusb_get_device_list] allocating new device for session [75]
[ 0.033955] [00004bd4] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.034088] [00004bd4] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.034188] [00004bd4] libusb: debug [winusb_get_device_list] allocating new device for session [76]
[ 0.034434] [00004bd4] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.034567] [00004bd4] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.034618] [00004bd4] libusb: debug [winusb_get_device_list] allocating new device for session [77]
[ 0.034921] [00004bd4] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_A36D&SUBSYS_091A1028&REV_10\3&11583659&0&A0' bus number 1
[ 0.035090] [00004bd4] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_15DB&SUBSYS_091A1028&REV_02\71D9F51854B3020000' bus number 2
[ 0.036563] [00004bd4] libusb: debug [winusb_get_device_list] found existing device for session [76]
[ 0.036787] [00004bd4] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.036909] [00004bd4] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 59 bytes)
[ 0.037057] [00004bd4] libusb: debug [init_device] (bus: 1, addr: 1, depth: 1, port: 2): 'USB\VID_046D&PID_C534\5&E9F3E45&0&2'
[ 0.037319] [00004bd4] libusb: debug [winusb_get_device_list] found existing device for session [16]
[ 0.037512] [00004bd4] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.037621] [00004bd4] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 200 bytes)
[ 0.037713] [00004bd4] libusb: debug [init_device] (bus: 1, addr: 5, depth: 1, port: 14): 'USB\VID_8087&PID_0AAA\5&E9F3E45&0&14'
[ 0.038627] [00004bd4] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\4&36020D6F&0&0' reports 26 ports
[ 0.038918] [00004bd4] libusb: debug [init_device] (bus: 1, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\4&36020D6F&0&0'
[ 0.039187] [00004bd4] libusb: debug [winusb_get_device_list] found existing device for session [77]
[ 0.039386] [00004bd4] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.039518] [00004bd4] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 269 bytes)
[ 0.039664] [00004bd4] libusb: debug [init_device] (bus: 1, addr: 4, depth: 1, port: 10): 'USB\VID_0A5C&PID_5842\0123456789ABCD'
[ 0.040054] [00004bd4] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\7&2452366F&0&0' reports 4 ports
[ 0.040178] [00004bd4] libusb: debug [init_device] (bus: 2, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\7&2452366F&0&0'
[ 0.040667] [00004bd4] libusb: debug [winusb_get_device_list] extra GUID: {209D0288-9C4C-5B63-3A38-9EBE14E03F48}
[ 0.040782] [00004bd4] libusb: debug [winusb_get_device_list] found existing device for session [24]
[ 0.040995] [00004bd4] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.041079] [00004bd4] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 44 bytes)
[ 0.041196] [00004bd4] libusb: debug [init_device] (bus: 1, addr: 13, depth: 1, port: 17): 'USB\VID_04B4&PID_00F0\5&E9F3E45&0&17'
[ 0.041760] [00004bd4] libusb: debug [winusb_get_device_list] extra GUID: {263CC669-8EB5-F923-ED1B-20580A530F01}
[ 0.041847] [00004bd4] libusb: debug [winusb_get_device_list] found existing device for session [74]
[ 0.042009] [00004bd4] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.042093] [00004bd4] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 114 bytes)
[ 0.042199] [00004bd4] libusb: debug [init_device] (bus: 1, addr: 3, depth: 1, port: 3): 'USB\VID_04B4&PID_0007\5&E9F3E45&0&3'
[ 0.042522] [00004bd4] libusb: debug [winusb_get_device_list] found existing device for session [75]
[ 0.042717] [00004bd4] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.042804] [00004bd4] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 1112 bytes)
[ 0.042910] [00004bd4] libusb: debug [init_device] (bus: 1, addr: 6, depth: 1, port: 11): 'USB\VID_0BDA&PID_58FD\200901010001'
[ 0.043376] [00004bd4] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL01\7&290AACAE&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.043517] [00004bd4] libusb: debug [winusb_get_device_list] setting composite interface for [76]:
[ 0.043565] [00004bd4] libusb: debug [set_composite_interface] interface[1] = \\?\HID#VID_046D&PID_C534&MI_01&COL01#7&E9A53E&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.043677] [00004bd4] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL01\5&99B72D3&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.043836] [00004bd4] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL03\5&379854AA&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.043960] [00004bd4] libusb: debug [winusb_get_device_list] setting composite interface for [76]:
[ 0.044033] [00004bd4] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL03\7&E9A53E&0&0002
[ 0.044136] [00004bd4] libusb: debug [winusb_get_device_list] setting composite interface for [76]:
[ 0.044212] [00004bd4] libusb: debug [set_composite_interface] interface[0] = \\?\HID#VID_046D&PID_C534&MI_00#7&286EBEEB&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}\KBD
[ 0.044317] [00004bd4] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL01\3&36A7043C&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.044458] [00004bd4] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\VID_044E&PID_1212&COL01&COL02\7&290AACAE&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.044583] [00004bd4] libusb: debug [winusb_get_device_list] setting composite interface for [76]:
[ 0.044632] [00004bd4] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL02\7&E9A53E&0&0001
[ 0.044738] [00004bd4] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\INTC816&COL02\3&36A7043C&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.044870] [00004bd4] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL02\5&99B72D3&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.044998] [00004bd4] libusb: debug [winusb_get_device_list] setting composite interface for [76]:
[ 0.045071] [00004bd4] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL05\7&E9A53E&0&0004
[ 0.045177] [00004bd4] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL02\5&379854AA&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.045281] [00004bd4] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL03\5&99B72D3&0&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.045386] [00004bd4] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL04\5&99B72D3&0&0003' (non USB HID, newly connected, etc.) - ignoring
[ 0.045489] [00004bd4] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\DELL091A&COL05\5&99B72D3&0&0004' (non USB HID, newly connected, etc.) - ignoring
[ 0.045584] [00004bd4] libusb: debug [winusb_get_device_list] setting composite interface for [76]:
[ 0.045637] [00004bd4] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL04\7&E9A53E&0&0003
[ 0.045744] [00004bd4] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\CONVERTEDDEVICE&COL01\5&379854AA&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.046379] [00004bd4] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.046463] [00004bd4] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.047665] [00004bd4] libusb: debug [libusb_get_device_descriptor]
[ 0.047728] [00004bd4] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.047829] [00004bd4] libusb: debug [libusb_get_device_descriptor]
[ 0.047881] [00004bd4] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.047961] [00004bd4] libusb: debug [libusb_get_device_descriptor]
[ 0.048013] [00004bd4] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.048058] [00004bd4] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.048130] [00004bd4] libusb: debug [libusb_get_device_descriptor]
[ 0.048180] [00004bd4] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.048254] [00004bd4] libusb: debug [libusb_get_device_descriptor]
[ 0.048304] [00004bd4] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.048349] [00004bd4] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.048416] [00004bd4] libusb: debug [libusb_get_device_descriptor]
[ 0.048467] [00004bd4] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.048511] [00004bd4] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.048555] [00004bd4] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.048621] [00004bd4] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.048674] [00004bd4] libusb: debug [libusb_unref_device] destroy device 1.5
[ 0.048722] [00004bd4] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.048768] [00004bd4] libusb: debug [libusb_unref_device] destroy device 2.0
[ 0.048813] [00004bd4] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.048856] [00004bd4] libusb: debug [libusb_unref_device] destroy device 1.6
[ 0.048935] [00004bd4] libusb: debug [libusb_open] open 1.13
[ 0.049036] [00004bd4] libusb: debug [libusb_claim_interface] interface 0
[ 0.049156] [00004bd4] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.049206] [00004bd4] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.049248] [00004bd4] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.049293] [00004bd4] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 01 to interface 0
[ 0.049339] [00004bd4] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.049508] [00004bd4] libusb: debug [libusb_submit_transfer] transfer 000002070DF426E8
[ 0.049559] [00004bd4] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 01 with interface 0
[ 0.049608] [00004bd4] libusb: debug [winusbx_submit_bulk_transfer] writing 100 bytes
[ 0.049682] [00004bd4] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.049730] [00004bd4] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.049776] [00004bd4] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[60.058690] [00004bd4] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 258
[60.058981] [00004bd4] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[60.059257] [00004bd4] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[120.069315] [00004bd4] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 258
[120.069641] [00004bd4] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[120.069908] [00004bd4] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
...
from python-libusb1.
Yes libusb sync transfer is internally based on async plus a blocking handle_events call.
https://github.com/libusb/libusb/blob/master/libusb/sync.c
I believe the device is okay as I tested with pyusb based code as well before using python-libusb1.
https://github.com/mcuee/python_usb/blob/master/cyusb_fx3_loopback-test_python3.py
pyusb/pyusb#235
I will try another device, probably Linux Gadegt Zero.
from python-libusb1.
I think you are right. I tried it again (but with another Windows 10 laptop at home) and it works fine (tested with libusb-1.0.23, 1.0.24 and latest git 1.0.24.11650). So I think the fixes are good.
There is a warning in the end of the debug log though. But I am not sure if it is an issue with libusb Windows or python-libusb1.
[ 0.103928] [00004f70] libusb: warning [libusb_exit] device 1.0 still referenced
Full debug log
(mypy39x64) PS C:\work\pyusb\python_usb> python .\cyusb_fx3_bulkloop_python_libusb1.py
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000312] [00004f70] libusb: debug [libusb_init] libusb v1.0.24.11650
[ 0.000465] [00004f70] libusb: debug [usbi_add_event_source] add HANDLE 0000000000000234 events 0
[ 0.000720] [00004f70] libusb: debug [usbi_io_init] using timer for timeouts
[ 0.000875] [00004f70] libusb: debug [usbi_add_event_source] add HANDLE 000000000000022C events 0
[ 0.001075] [00004f70] libusb: debug [get_windows_version] Windows 10 64-bit
[ 0.001242] [00004f70] libusb: debug [htab_create] using 1021 entries hash table
[ 0.003240] [00004f70] libusb: info [winusbx_init] WinUSB DLL available (with isoch support)
[ 0.004519] [00004f70] libusb: debug [winusbx_init] libusbK DLL found, version: 3.1.0.0
[ 0.010862] [00004f70] libusb: debug [windows_init] UsbDk backend is available
[ 0.011438] [00004f70] libusb: debug [libusb_get_device_list]
[ 0.012893] [00003fa0] libusb: debug [windows_iocp_thread] I/O completion thread started
[ 0.024828] [00004f70] libusb: debug [winusb_get_device_list] allocating new device for session [5A]
[ 0.025247] [00004f70] libusb: debug [get_api_type] driver(s): BTHUSB
[ 0.025438] [00004f70] libusb: debug [get_api_type] lower filter driver(s): ibtusb
[ 0.025601] [00004f70] libusb: debug [winusb_get_device_list] allocating new device for session [3]
[ 0.026166] [00004f70] libusb: debug [get_api_type] driver(s): RTSUER
[ 0.026354] [00004f70] libusb: debug [winusb_get_device_list] allocating new device for session [25]
[ 0.026873] [00004f70] libusb: debug [get_api_type] driver(s): WUDFRd
[ 0.027125] [00004f70] libusb: debug [get_api_type] lower filter driver(s): WinUsb
[ 0.027298] [00004f70] libusb: debug [get_api_type] matched lower filter driver name against WinUSB
[ 0.027440] [00004f70] libusb: debug [winusb_get_device_list] allocating new device for session [42]
[ 0.027780] [00004f70] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.028051] [00004f70] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.028122] [00004f70] libusb: debug [winusb_get_device_list] allocating new device for session [43]
[ 0.028341] [00004f70] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.028516] [00004f70] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.028665] [00004f70] libusb: debug [winusb_get_device_list] allocating new device for session [44]
[ 0.029044] [00004f70] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.029295] [00004f70] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.029466] [00004f70] libusb: debug [winusb_get_device_list] allocating new device for session [45]
[ 0.030027] [00004f70] libusb: debug [enumerate_hcd_root_hub] assigning HCD 'PCI\VEN_8086&DEV_9D2F&SUBSYS_118C1025&REV_21\3&11583659&0&A0' bus number 1
[ 0.031285] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [42]
[ 0.031609] [00004f70] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.031775] [00004f70] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 32 bytes)
[ 0.031931] [00004f70] libusb: debug [init_device] (bus: 1, addr: 14, depth: 1, port: 9): 'USB\VID_1C7A&PID_0570\5&37630CAE&0&9'
[ 0.032160] [00004f70] libusb: debug [winusb_get_device_list] extra GUID: {C2F29381-1A77-AE60-52EE-F118044DB852}
[ 0.032299] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [45]
[ 0.032535] [00004f70] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.032684] [00004f70] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 44 bytes)
[ 0.032865] [00004f70] libusb: debug [init_device] (bus: 1, addr: 22, depth: 1, port: 13): 'USB\VID_04B4&PID_00F0\5&37630CAE&0&13'
[ 0.033220] [00004f70] libusb: debug [init_root_hub] root hub 'USB\ROOT_HUB30\4&34F93CAD&0&0' reports 18 ports
[ 0.033426] [00004f70] libusb: debug [init_device] (bus: 1, addr: 0, depth: 0, port: 0): 'USB\ROOT_HUB30\4&34F93CAD&0&0'
[ 0.033611] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [3]
[ 0.033828] [00004f70] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.033998] [00004f70] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 200 bytes)
[ 0.034213] [00004f70] libusb: debug [init_device] (bus: 1, addr: 3, depth: 1, port: 6): 'USB\VID_8087&PID_0029\5&37630CAE&0&6'
[ 0.034662] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [44]
[ 0.034862] [00004f70] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.035004] [00004f70] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 577 bytes)
[ 0.035163] [00004f70] libusb: debug [init_device] (bus: 1, addr: 1, depth: 1, port: 7): 'USB\VID_04F2&PID_B5F7\5&37630CAE&0&7'
[ 0.035416] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [43]
[ 0.035644] [00004f70] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.035784] [00004f70] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 59 bytes)
[ 0.035922] [00004f70] libusb: debug [init_device] (bus: 1, addr: 4, depth: 1, port: 5): 'USB\VID_046D&PID_C534\5&37630CAE&0&5'
[ 0.036148] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [25]
[ 0.036365] [00004f70] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.036527] [00004f70] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 39 bytes)
[ 0.036759] [00004f70] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 8): 'USB\VID_0BDA&PID_0129\20100201396000000'
[ 0.037182] [00004f70] libusb: debug [winusb_get_device_list] setting composite interface for [43]:
[ 0.037290] [00004f70] libusb: debug [set_composite_interface] interface[1] = \\?\HID#VID_046D&PID_C534&MI_01&COL01#7&2FA52F82&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.037483] [00004f70] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\ELAN0501&COL01\5&10870616&1&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.037693] [00004f70] libusb: debug [winusb_get_device_list] setting composite interface for [43]:
[ 0.037826] [00004f70] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL03\7&2FA52F82&0&0002
[ 0.038019] [00004f70] libusb: debug [winusb_get_device_list] setting composite interface for [43]:
[ 0.038139] [00004f70] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL02\7&2FA52F82&0&0001
[ 0.038272] [00004f70] libusb: debug [winusb_get_device_list] setting composite interface for [43]:
[ 0.038373] [00004f70] libusb: debug [set_composite_interface] interface[0] = \\?\HID#VID_046D&PID_C534&MI_00#7&73A81B9&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}\KBD
[ 0.038528] [00004f70] libusb: debug [winusb_get_device_list] setting composite interface for [43]:
[ 0.038630] [00004f70] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL04\7&2FA52F82&0&0003
[ 0.038787] [00004f70] libusb: debug [winusb_get_device_list] setting composite interface for [43]:
[ 0.038899] [00004f70] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL05\7&2FA52F82&0&0004
[ 0.039114] [00004f70] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\ELAN0501&COL02\5&10870616&1&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.039288] [00004f70] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\ELAN0501&COL03\5&10870616&1&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.039452] [00004f70] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\ELAN0501&COL04\5&10870616&1&0003' (non USB HID, newly connected, etc.) - ignoring
[ 0.039604] [00004f70] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\HIDCLASS&COL01\1&2D595CA7&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.039766] [00004f70] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\HIDCLASS&COL02\1&2D595CA7&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.040907] [00004f70] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.041108] [00004f70] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.041790] [00004f70] libusb: debug [libusb_get_device_descriptor]
[ 0.041945] [00004f70] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.042108] [00004f70] libusb: debug [libusb_get_device_descriptor]
[ 0.042234] [00004f70] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.042457] [00004f70] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.042633] [00004f70] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.042776] [00004f70] libusb: debug [libusb_unref_device] destroy device 1.14
[ 0.042890] [00004f70] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.043010] [00004f70] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.043127] [00004f70] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.043246] [00004f70] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.043406] [00004f70] libusb: debug [libusb_open] open 1.22
[ 0.043642] [00004f70] libusb: debug [libusb_claim_interface] interface 0
[ 0.043869] [00004f70] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.044009] [00004f70] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.044122] [00004f70] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.044239] [00004f70] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 01 to interface 0
[ 0.044367] [00004f70] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.044718] [00004f70] libusb: debug [libusb_submit_transfer] transfer 0000021B1288D668
[ 0.044797] [00004f70] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 01 with interface 0
[ 0.044898] [00004f70] libusb: debug [winusbx_submit_bulk_transfer] writing 100 bytes
[ 0.045041] [00004f70] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.045186] [00004f70] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.045310] [00004f70] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.045151] [00003fa0] libusb: debug [windows_iocp_thread] transfer 0000021B1288D668 completed, length 100
[ 0.045515] [00004f70] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.045644] [00004f70] libusb: debug [handle_event_trigger] event triggered
[ 0.045767] [00004f70] libusb: debug [windows_handle_transfer_completion] handling transfer 0000021B1288D668 completion with errcode 0, length 100
[ 0.045914] [00004f70] libusb: debug [usbi_handle_transfer_completion] transfer 0000021B1288D668 has callback 00007FFFCE729220
[ 0.046046] [00004f70] libusb: debug [sync_transfer_cb] actual_length=100
[ 0.046173] [00004f70] libusb: debug [libusb_free_transfer] transfer 0000021B1288D668
[ 0.046340] [00004f70] libusb: debug [libusb_release_interface] interface 0
Number of bytes written: 100
[ 0.046641] [00004f70] libusb: debug [libusb_close]
write: True
[ 0.046947] [00004f70] libusb: debug [libusb_get_device_list]
[ 0.057297] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [5A]
[ 0.057695] [00004f70] libusb: debug [get_api_type] driver(s): BTHUSB
[ 0.057896] [00004f70] libusb: debug [get_api_type] lower filter driver(s): ibtusb
[ 0.058062] [00004f70] libusb: debug [winusb_get_device_list] allocating new device for session [3]
[ 0.058655] [00004f70] libusb: debug [get_api_type] driver(s): RTSUER
[ 0.058833] [00004f70] libusb: debug [winusb_get_device_list] allocating new device for session [25]
[ 0.059319] [00004f70] libusb: debug [get_api_type] driver(s): WUDFRd
[ 0.059518] [00004f70] libusb: debug [get_api_type] lower filter driver(s): WinUsb
[ 0.059664] [00004f70] libusb: debug [get_api_type] matched lower filter driver name against WinUSB
[ 0.059734] [00004f70] libusb: debug [winusb_get_device_list] allocating new device for session [42]
[ 0.060094] [00004f70] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.060324] [00004f70] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.060471] [00004f70] libusb: debug [winusb_get_device_list] allocating new device for session [43]
[ 0.060817] [00004f70] libusb: debug [get_api_type] driver(s): usbccgp
[ 0.061036] [00004f70] libusb: debug [get_api_type] matched driver name against Composite API
[ 0.061176] [00004f70] libusb: debug [winusb_get_device_list] allocating new device for session [44]
[ 0.061463] [00004f70] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.061605] [00004f70] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.061731] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [45]
[ 0.063493] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [42]
[ 0.063764] [00004f70] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.063952] [00004f70] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 32 bytes)
[ 0.064068] [00004f70] libusb: debug [init_device] (bus: 1, addr: 14, depth: 1, port: 9): 'USB\VID_1C7A&PID_0570\5&37630CAE&0&9'
[ 0.064319] [00004f70] libusb: debug [winusb_get_device_list] extra GUID: {C2F29381-1A77-AE60-52EE-F118044DB852}
[ 0.064473] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [45]
[ 0.064885] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [3]
[ 0.065142] [00004f70] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.065371] [00004f70] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 200 bytes)
[ 0.065524] [00004f70] libusb: debug [init_device] (bus: 1, addr: 3, depth: 1, port: 6): 'USB\VID_8087&PID_0029\5&37630CAE&0&6'
[ 0.065979] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [44]
[ 0.066194] [00004f70] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.066343] [00004f70] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 577 bytes)
[ 0.066502] [00004f70] libusb: debug [init_device] (bus: 1, addr: 1, depth: 1, port: 7): 'USB\VID_04F2&PID_B5F7\5&37630CAE&0&7'
[ 0.066765] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [43]
[ 0.066968] [00004f70] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.067113] [00004f70] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 59 bytes)
[ 0.067254] [00004f70] libusb: debug [init_device] (bus: 1, addr: 4, depth: 1, port: 5): 'USB\VID_046D&PID_C534\5&37630CAE&0&5'
[ 0.067449] [00004f70] libusb: debug [winusb_get_device_list] found existing device for session [25]
[ 0.067652] [00004f70] libusb: debug [init_device] found 1 configurations (current config: 1)
[ 0.067849] [00004f70] libusb: debug [cache_config_descriptors] cached config descriptor 0 (bConfigurationValue=1, 39 bytes)
[ 0.067983] [00004f70] libusb: debug [init_device] (bus: 1, addr: 2, depth: 1, port: 8): 'USB\VID_0BDA&PID_0129\20100201396000000'
[ 0.068355] [00004f70] libusb: debug [winusb_get_device_list] setting composite interface for [43]:
[ 0.068466] [00004f70] libusb: debug [set_composite_interface] interface[1] = \\?\HID#VID_046D&PID_C534&MI_01&COL01#7&2FA52F82&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}
[ 0.068659] [00004f70] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\ELAN0501&COL01\5&10870616&1&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.068854] [00004f70] libusb: debug [winusb_get_device_list] setting composite interface for [43]:
[ 0.068988] [00004f70] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL03\7&2FA52F82&0&0002
[ 0.069399] [00004f70] libusb: debug [winusb_get_device_list] setting composite interface for [43]:
[ 0.069534] [00004f70] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL02\7&2FA52F82&0&0001
[ 0.069713] [00004f70] libusb: debug [winusb_get_device_list] setting composite interface for [43]:
[ 0.069844] [00004f70] libusb: debug [set_composite_interface] interface[0] = \\?\HID#VID_046D&PID_C534&MI_00#7&73A81B9&0&0000#{4D1E55B2-F16F-11CF-88CB-001111000030}\KBD
[ 0.070025] [00004f70] libusb: debug [winusb_get_device_list] setting composite interface for [43]:
[ 0.070156] [00004f70] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL04\7&2FA52F82&0&0003
[ 0.070341] [00004f70] libusb: debug [winusb_get_device_list] setting composite interface for [43]:
[ 0.070498] [00004f70] libusb: debug [set_composite_interface] interface[1] already set - ignoring HID collection: HID\VID_046D&PID_C534&MI_01&COL05\7&2FA52F82&0&0004
[ 0.070691] [00004f70] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\ELAN0501&COL02\5&10870616&1&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.070875] [00004f70] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\ELAN0501&COL03\5&10870616&1&0002' (non USB HID, newly connected, etc.) - ignoring
[ 0.071054] [00004f70] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\ELAN0501&COL04\5&10870616&1&0003' (non USB HID, newly connected, etc.) - ignoring
[ 0.071214] [00004f70] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\HIDCLASS&COL01\1&2D595CA7&0&0000' (non USB HID, newly connected, etc.) - ignoring
[ 0.071379] [00004f70] libusb: debug [winusb_get_device_list] unlisted ancestor for 'HID\HIDCLASS&COL02\1&2D595CA7&0&0001' (non USB HID, newly connected, etc.) - ignoring
[ 0.072376] [00004f70] libusb: debug [get_api_type] driver(s): WinUSB
[ 0.072558] [00004f70] libusb: debug [get_api_type] matched driver name against WinUSB
[ 0.073214] [00004f70] libusb: debug [libusb_get_device_descriptor]
[ 0.073347] [00004f70] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.073515] [00004f70] libusb: debug [libusb_get_device_descriptor]
[ 0.073655] [00004f70] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.073787] [00004f70] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.073930] [00004f70] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.074071] [00004f70] libusb: debug [libusb_unref_device] destroy device 1.14
[ 0.074177] [00004f70] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.074287] [00004f70] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.074397] [00004f70] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.074513] [00004f70] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.074626] [00004f70] libusb: debug [libusb_open] open 1.22
[ 0.074776] [00004f70] libusb: debug [libusb_claim_interface] interface 0
[ 0.074957] [00004f70] libusb: debug [winusbx_claim_interface] claimed interface 0
[ 0.075065] [00004f70] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.075176] [00004f70] libusb: debug [parse_endpoint] skipping descriptor 0x30
[ 0.075282] [00004f70] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 01 to interface 0
[ 0.075389] [00004f70] libusb: debug [windows_assign_endpoints] (re)assigned endpoint 81 to interface 0
[ 0.075701] [00004f70] libusb: debug [libusb_submit_transfer] transfer 0000021B1447FA78
[ 0.075815] [00004f70] libusb: debug [add_to_flying_list] arm timer for timeout in 10ms (first in line)
[ 0.075914] [00004f70] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 81 with interface 0
[ 0.076005] [00004f70] libusb: debug [winusbx_submit_bulk_transfer] reading 1024 bytes
[ 0.076179] [00004f70] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.076245] [00003fa0] libusb: debug [windows_iocp_thread] transfer 0000021B1447FA78 completed, length 100
[ 0.076258] [00004f70] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.076413] [00004f70] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.076458] [00004f70] libusb: debug [handle_event_trigger] event triggered
[ 0.076500] [00004f70] libusb: debug [windows_handle_transfer_completion] handling transfer 0000021B1447FA78 completion with errcode 0, length 100
[ 0.076561] [00004f70] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.076608] [00004f70] libusb: debug [usbi_handle_transfer_completion] transfer 0000021B1447FA78 has callback 00007FFFCE729220
[ 0.076667] [00004f70] libusb: debug [sync_transfer_cb] actual_length=100
[ 0.076713] [00004f70] libusb: debug [libusb_free_transfer] transfer 0000021B1447FA78
[ 0.076781] [00004f70] libusb: debug [libusb_submit_transfer] transfer 0000021B1447FFB8
[ 0.076874] [00004f70] libusb: debug [add_to_flying_list] arm timer for timeout in 10ms (first in line)
[ 0.076964] [00004f70] libusb: debug [winusbx_submit_bulk_transfer] matched endpoint 81 with interface 0
[ 0.077049] [00004f70] libusb: debug [winusbx_submit_bulk_transfer] reading 1024 bytes
[ 0.077147] [00004f70] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.077222] [00004f70] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.096111] [00004f70] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 1
[ 0.096419] [00004f70] libusb: debug [libusb_cancel_transfer] transfer 0000021B1447FFB8
[ 0.096690] [00004f70] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.096817] [00003fa0] libusb: debug [windows_iocp_thread] transfer 0000021B1447FFB8 completed, length 0
[ 0.097002] [00004f70] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.097560] [00004f70] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() for 2 HANDLEs with timeout in 60000ms
[ 0.097823] [00004f70] libusb: debug [usbi_wait_for_events] WaitForMultipleObjects() returned 0
[ 0.098047] [00004f70] libusb: debug [handle_event_trigger] event triggered
[ 0.098251] [00004f70] libusb: debug [windows_handle_transfer_completion] handling transfer 0000021B1447FFB8 completion with errcode 995, length 0
[ 0.098493] [00004f70] libusb: debug [windows_handle_transfer_completion] detected operation aborted
[ 0.098669] [00004f70] libusb: debug [usbi_handle_transfer_cancellation] detected timeout cancellation
[ 0.098889] [00004f70] libusb: debug [arm_timer_for_next_timeout] no timeouts, disarming timer
[ 0.099120] [00004f70] libusb: debug [usbi_handle_transfer_completion] transfer 0000021B1447FFB8 has callback 00007FFFCE729220
[ 0.099356] [00004f70] libusb: debug [sync_transfer_cb] actual_length=0
[ 0.099562] [00004f70] libusb: debug [libusb_free_transfer] transfer 0000021B1447FFB8
[ 0.099800] [00004f70] libusb: debug [libusb_release_interface] interface 0
[ 0.100041] [00004f70] libusb: debug [libusb_close]
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
Closing USB
[ 0.100834] [00004f70] libusb: error [libusb_set_pollfd_notifiers] external polling of libusb's internal event sources is not yet supported on Windows
[ 0.101129] [00004f70] libusb: debug [libusb_unref_device] destroy device 1.22
[ 0.101370] [00004f70] libusb: debug [libusb_exit]
[ 0.101602] [00003fa0] libusb: debug [windows_iocp_thread] I/O completion thread exiting
[ 0.103509] [00004f70] libusb: debug [usbi_remove_event_source] remove HANDLE 000000000000022C
[ 0.103736] [00004f70] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000234
[ 0.103928] [00004f70] libusb: warning [libusb_exit] device 1.0 still referenced
Close handle successfully
Calling closing method to delete self
Closing USB
Close handle successfully
from python-libusb1.
And your example works fine as well under my OrangePi Zero with old Python 3.5 and ARMBIAN 5.60 stable Debian GNU/Linux 9 (stretch) 4.14.70-sunxi.
OrangePi Zero Linux USB Gadget
mcuee@orangepizero:~/usbgadgests/python-functionfs$ sudo python3 examples/usbcat/device.py
epoll: fd 3 got event 1
onBind
epoll: fd 3 got event 1
onEnable
epoll: fd 3 got event 1
aio read completion received 100 bytes
epoll: fd 3 got event 1
aio read completion received 100 bytes
Windows 10 host
(mypy39x64) PS C:\work\pyusb> python .\test_functionfs.py
Number of bytes written: 100
write: True
read: bytearray(b'')
Closing USB
Close handle successfully
Calling closing method to delete self
Closing USB
Close handle successfully
from python-libusb1.
[ 0.103928] [00004f70] libusb: warning [libusb_exit] device 1.0 still referenced
This is indeed a bit surprising. In a previous try (with explicit gc.collect()
calls) it did not happen, device 1.0 got somehow destroyed. No such device appear in my case (maybe running in a VM makes a difference ?). I'll try to see if I can reproduce this and identify what device this is.
I now consider my changes to be in the right direction, so I pushed them to master and dropped the wip
branch. Thanks a lot for your patient testing !
And your example works fine as well under my OrangePi Zero with old Python 3.5 and ARMBIAN 5.60 stable Debian GNU/Linux 9 (stretch) 4.14.70-sunxi.
Awesome. So far I personally have only run it on an intel edison (udc=DWC3 but without companion chip for USB3 support and some quirks - some endpoints do not work) and on a raspberry pi zero (udc=DWC2). Good to know that it is working on more gadget-able devices.
from python-libusb1.
[ 0.103928] [00004f70] libusb: warning [libusb_exit] device 1.0 still referenced
This is indeed a bit surprising. In a previous try (with explicit
gc.collect()
calls) it did not happen, device 1.0 got somehow destroyed. No such device appear in my case (maybe running in a VM makes a difference ?). I'll try to see if I can reproduce this and identify what device this is.
If you look at your Windows 10 debug log, you will notice the following about 'some libusb_devices were leaked'. You are using libusb-1.0.24 release which gives this debug log. libusb-1.0 git now gives more detailed information about which devices were leaked.
And then there is an error in the debug log as well.
error [libusb_set_pollfd_notifiers] external polling of libusb's internal event sources is not yet supported on Windows
.
Closing USB
[ 0.064870] [000003b4] libusb: error [libusb_set_pollfd_notifiers] external polling of libusb's internal event sources is not yet supported on Windows
[ 0.065282] [000003b4] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.065452] [000003b4] libusb: debug [libusb_exit]
[ 0.065708] [000003b4] libusb: debug [libusb_exit] destroying default context
[ 0.065967] [000003b4] libusb: warning [libusb_exit] some libusb_devices were leaked
[ 0.066258] [000003b4] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000238
[ 0.066573] [000003b4] libusb: debug [usbi_remove_event_source] remove HANDLE 0000000000000120
[ 0.066951] [0000117c] libusb: debug [windows_iocp_thread] I/O completion thread exiting
Close handle successfully
Calling closing method to delete self
Closing USB
Close handle successfully
I now consider my changes to be in the right direction, so I pushed them to master and dropped the
wip
branch. Thanks a lot for your patient testing !
Great,
from python-libusb1.
I think you are right. I tried it again (but with another Windows 10 laptop at home) and it works fine (tested with libusb-1.0.23, 1.0.24 and latest git 1.0.24.11650). So I think the fixes are good.
Going back to my original Windows 10 laptop and it also works fine, tested with latest git head now that you have integrated the patches.
(py39venv) C:\work\libusb\python_usb [master ≡ +9 ~0 -0 !]> $Env:LIBUSB_DEBUG=3
(py39venv) C:\work\libusb\python_usb [master ≡ +9 ~0 -0 !]> python .\cyusb_fx3_bulkloop_python_libusb1.py
libusb: info [winusbx_init] WinUSB DLL available (with isoch support)
libusb: error [load_usbdk_helper_dll] Failed to load UsbDkHelper.dll: [126] The specified module could not be found.
libusb: info [windows_init] UsbDk backend is not available
Number of bytes written: 100
write: True
read: bytearray(b'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB')
Closing USB
libusb: error [libusb_set_pollfd_notifiers] external polling of libusb's internal event sources is not yet supported on Windows
libusb: warning [libusb_exit] device 1.0 still referenced
Close handle successfully
Calling closing method to delete self
Closing USB
Close handle successfully
from python-libusb1.
This libusb: error [libusb_set_pollfd_notifiers] external polling of libusb's internal event sources is not yet supported on Windows
probably needs to be fixed.
The libusb: warning [libusb_exit] device 1.0 still referenced
warning message may or may not be a problem with python-libusb1.
Reference: libusb/libusb#974 and libusb/libusb#988
from python-libusb1.
I will create a separate issue with the device leak issue.
from python-libusb1.
Yes the latest git fixed the warning, Thanks.
I think you can closed this whole issue.
from python-libusb1.
Thanks for the contribution.
I will test it with my device and will report if I got any issues.
from python-libusb1.
I'm closing this, but please do reopen if you find that it is not fixed.
from python-libusb1.
Related Issues (20)
- threading.Condition.notifyAll has been deprecated in favour of notify_all in Python 3.10 HOT 1
- Getting OSError in dlopen with the libusb-1.0.dylib installed by homebrew for Apple M1
- libusb_set_option support HOT 23
- Device Leak Issue under Windows HOT 10
- OSError: dlopen failed: library "libusb-1.0.so" not found HOT 4
- build fails against setuptools 58+ HOT 8
- 2.0.1 fails to build with Python 3.11.0a2 HOT 5
- question: comparison with pyusb HOT 2
- Do the bulk transfer APIs handle fragmentation? HOT 3
- Segmentation fault on every function call HOT 3
- libusb stress_mt.c conversion to python-libusb1 HOT 9
- Event handler context HOT 3
- Needs a binding for libusb_interrupt_event_handler HOT 5
- How to set `libusb_transfer.flags` HOT 2
- Feature request: USBContext.handleEventsCompleted() HOT 3
- Fix Release Signatures on PyPI (404 Not Found) HOT 5
- Errors on Windows HOT 2
- `ValueError` in a finalizer on PyPy HOT 4
- UsbDK support HOT 3
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 python-libusb1.