question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't change configuration: [Errno 16] Resource busy

See original GitHub issue

Bear with me a second, I know there has been lots of “Resource busy” issues in this project and the Internet, namely Stack Overflow, is also full to the brim with them. Nevertheless, I’d still need some help here because I’m genuinely lost.

My code is as follows and its objective is simple: Check which configuration is this device configured on currently and change it to the second one. The specific device I hard-coded does indeed have that second configuration available.

import usb.core
import usb.util
import usb.control

# find our device
dev = usb.core.find(idVendor=0x04e8, idProduct=0x6860)

# was it found?
if dev is None:
    raise ValueError('Device not found')
   
#test change config
try:
    cfg = dev.get_active_configuration()
except usb.core.USBError:
    cfg = None
if cfg is None or cfg.bConfigurationValue != 2:
    for intf in cfg:
    	print(intf)
    	print(dev.is_kernel_driver_active(intf.bInterfaceNumber))
    	dev.detach_kernel_driver(intf.bInterfaceNumber)
    	usb.util.claim_interface(dev, intf.bInterfaceNumber)

dev.set_configuration(2)

Code right now is not made to be 100% functional but to test this possible bug/user error. Its current issues are:

  1. print(intf) prints the current interface.
  2. is_kernel_driver_active() prints False.
  3. detach_kernel_driver() throws [Errno 2] Entity not found.
  4. claim_interface() throws [Errno 16] Resource busy.

As you can see, the code works erratically and, to the best of my knowledge, even contradicts itself. To be extra sure, I swapped my code a couple times and implemented several solutions, for example this one stated in Issue #76, here. This specific solution made my code jump straight to dev.set_configuration(2) because the condition at the innermost if loop was always False, which throws yet another [Errno 16] Resource busy. Aside from this error, dmesg also shows me the following when running the previous solution or jumping straight to dev.set_configuration(2):

[ 5483.405249] usb 1-4: usbfs: interface 0 claimed by usbfs while 'python3' sets config #2

I’ve used pyusb before and I’m well aquainted with how it works, specifically control transfers, but to be extra careful, I decided to read libusb’s FAQ, pyusb’s FAQ and Configuration selection and handling.

After making sure I understood everything I was doing, I decided to debug the code myself using LIBUSB_DEBUG=4 and PYUSB_DEBUG=debug. This is my code’s stderr along with the program’s stdout (minus the prints to avoid visual cluttering):

2021-09-28 12:29:00,302 DEBUG:usb.backend.libusb1:_LibUSB.__init__(<CDLL 'libusb-1.0.so.0', handle b808b0 at 0x7f7d06cc3ee0>)
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000005] [00001b3a] libusb: debug [libusb_init] created default context
[ 0.000023] [00001b3a] libusb: debug [libusb_init] libusb v1.0.23.11397
[ 0.000052] [00001b3a] libusb: debug [find_usbfs_path] found usbfs at /dev/bus/usb
[ 0.000069] [00001b3a] libusb: debug [get_kernel_version] reported kernel version is 5.11.0-36-generic
[ 0.000074] [00001b3a] libusb: debug [op_init] bulk continuation flag supported
[ 0.000077] [00001b3a] libusb: debug [op_init] zero length packet flag supported
[ 0.000081] [00001b3a] libusb: debug [op_init] max iso packet length is (likely) 49152 bytes
[ 0.000094] [00001b3a] libusb: debug [op_init] sysfs can relate devices
[ 0.000099] [00001b3a] libusb: debug [op_init] sysfs has complete descriptors
[ 0.000574] [00001b3c] libusb: debug [linux_udev_event_thread_main] udev event thread entering.
[ 0.004934] [00001b3a] libusb: debug [linux_get_device_address] getting address for device: usb1 detached: 0
[ 0.004955] [00001b3a] libusb: debug [linux_get_device_address] scan usb1
[ 0.004989] [00001b3a] libusb: debug [linux_get_device_address] bus=1 dev=1
[ 0.004995] [00001b3a] libusb: debug [linux_enumerate_device] busnum 1 devaddr 1 session_id 257
[ 0.004999] [00001b3a] libusb: debug [linux_enumerate_device] allocating new device for 1/1 (session 257)
[ 0.005106] [00001b3a] libusb: debug [linux_get_device_address] getting address for device: 1-12 detached: 0
[ 0.005116] [00001b3a] libusb: debug [linux_get_device_address] scan 1-12
[ 0.005141] [00001b3a] libusb: debug [linux_get_device_address] bus=1 dev=3
[ 0.005145] [00001b3a] libusb: debug [linux_enumerate_device] busnum 1 devaddr 3 session_id 259
[ 0.005150] [00001b3a] libusb: debug [linux_enumerate_device] allocating new device for 1/3 (session 259)
[ 0.005176] [00001b3a] libusb: debug [linux_get_parent_info] Dev 0xba4220 (1-12) has parent 0xba43d0 (usb1) port 12
[ 0.005250] [00001b3a] libusb: debug [linux_get_device_address] getting address for device: 1-4 detached: 0
[ 0.005255] [00001b3a] libusb: debug [linux_get_device_address] scan 1-4
[ 0.005282] [00001b3a] libusb: debug [linux_get_device_address] bus=1 dev=6
[ 0.005286] [00001b3a] libusb: debug [linux_enumerate_device] busnum 1 devaddr 6 session_id 262
[ 0.005291] [00001b3a] libusb: debug [linux_enumerate_device] allocating new device for 1/6 (session 262)
[ 0.005315] [00001b3a] libusb: debug [linux_get_parent_info] Dev 0xba4780 (1-4) has parent 0xba43d0 (usb1) port 4
[ 0.005384] [00001b3a] libusb: debug [linux_get_device_address] getting address for device: usb2 detached: 0
[ 0.005389] [00001b3a] libusb: debug [linux_get_device_address] scan usb2
[ 0.005417] [00001b3a] libusb: debug [linux_get_device_address] bus=2 dev=1
[ 0.005421] [00001b3a] libusb: debug [linux_enumerate_device] busnum 2 devaddr 1 session_id 513
[ 0.005430] [00001b3a] libusb: debug [linux_enumerate_device] allocating new device for 2/1 (session 513)
[ 0.005522] [00001b3a] libusb: debug [linux_get_device_address] getting address for device: usb3 detached: 0
[ 0.005531] [00001b3a] libusb: debug [linux_get_device_address] scan usb3
[ 0.005556] [00001b3a] libusb: debug [linux_get_device_address] bus=3 dev=1
[ 0.005559] [00001b3a] libusb: debug [linux_enumerate_device] busnum 3 devaddr 1 session_id 769
[ 0.005563] [00001b3a] libusb: debug [linux_enumerate_device] allocating new device for 3/1 (session 769)
[ 0.005657] [00001b3a] libusb: debug [linux_get_device_address] getting address for device: 3-2 detached: 0
[ 0.005666] [00001b3a] libusb: debug [linux_get_device_address] scan 3-2
[ 0.005692] [00001b3a] libusb: debug [linux_get_device_address] bus=3 dev=2
[ 0.005695] [00001b3a] libusb: debug [linux_enumerate_device] busnum 3 devaddr 2 session_id 770
[ 0.005698] [00001b3a] libusb: debug [linux_enumerate_device] allocating new device for 3/2 (session 770)
[ 0.005722] [00001b3a] libusb: debug [linux_get_parent_info] Dev 0xba4af0 (3-2) has parent 0xba49e0 (usb3) port 2
[ 0.005799] [00001b3a] libusb: debug [linux_get_device_address] getting address for device: usb4 detached: 0
[ 0.005806] [00001b3a] libusb: debug [linux_get_device_address] scan usb4
[ 0.005832] [00001b3a] libusb: debug [linux_get_device_address] bus=4 dev=1
[ 0.005835] [00001b3a] libusb: debug [linux_enumerate_device] busnum 4 devaddr 1 session_id 1025
[ 0.005838] [00001b3a] libusb: debug [linux_enumerate_device] allocating new device for 4/1 (session 1025)
[ 0.005928] [00001b3a] libusb: debug [linux_get_device_address] getting address for device: usb5 detached: 0
[ 0.005936] [00001b3a] libusb: debug [linux_get_device_address] scan usb5
[ 0.005961] [00001b3a] libusb: debug [linux_get_device_address] bus=5 dev=1
[ 0.005964] [00001b3a] libusb: debug [linux_enumerate_device] busnum 5 devaddr 1 session_id 1281
[ 0.005967] [00001b3a] libusb: debug [linux_enumerate_device] allocating new device for 5/1 (session 1281)
[ 0.006061] [00001b3a] libusb: debug [linux_get_device_address] getting address for device: 5-1 detached: 0
[ 0.006069] [00001b3a] libusb: debug [linux_get_device_address] scan 5-1
[ 0.006096] [00001b3a] libusb: debug [linux_get_device_address] bus=5 dev=2
[ 0.006100] [00001b3a] libusb: debug [linux_enumerate_device] busnum 5 devaddr 2 session_id 1282
[ 0.006103] [00001b3a] libusb: debug [linux_enumerate_device] allocating new device for 5/2 (session 1282)
[ 0.006126] [00001b3a] libusb: debug [linux_get_parent_info] Dev 0xba4e50 (5-1) has parent 0xba4d40 (usb5) port 1
[ 0.006198] [00001b3a] libusb: debug [linux_get_device_address] getting address for device: usb6 detached: 0
[ 0.006204] [00001b3a] libusb: debug [linux_get_device_address] scan usb6
[ 0.006230] [00001b3a] libusb: debug [linux_get_device_address] bus=6 dev=1
[ 0.006235] [00001b3a] libusb: debug [linux_enumerate_device] busnum 6 devaddr 1 session_id 1537
[ 0.006239] [00001b3a] libusb: debug [linux_enumerate_device] allocating new device for 6/1 (session 1537)
[ 0.006385] [00001b3a] libusb: debug [usbi_add_pollfd] add fd 6 events 1
[ 0.006407] [00001b3a] libusb: debug [usbi_io_init] using timerfd for timeouts
[ 0.006412] [00001b3a] libusb: debug [usbi_add_pollfd] add fd 8 events 1
2021-09-28 12:29:00,309 INFO:usb.core:find(): using backend "usb.backend.libusb1"
2021-09-28 12:29:00,309 DEBUG:usb.backend.libusb1:_LibUSB.enumerate_devices()
[ 0.006891] [00001b3a] libusb: debug [libusb_get_device_list] 
[ 0.006910] [00001b3a] libusb: debug [discovered_devs_append] need to increase capacity
2021-09-28 12:29:00,309 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f7d0695cc10>)
[ 0.007143] [00001b3a] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:29:00,309 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f7d0695cdc0>)
[ 0.007420] [00001b3a] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:29:00,310 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f7d0695cca0>)
[ 0.007672] [00001b3a] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:29:00,310 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f7d0695ce20>)
[ 0.007872] [00001b3a] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:29:00,310 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f7d0695cd30>)
[ 0.008068] [00001b3a] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:29:00,310 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f7d0695ce80>)
[ 0.008269] [00001b3a] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:29:00,311 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f7d0695cc70>)
[ 0.008466] [00001b3a] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:29:00,311 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f7d0695cdf0>)
[ 0.008670] [00001b3a] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:29:00,311 DEBUG:usb.backend.libusb1:_LibUSB.open_device(<usb.backend.libusb1._Device object at 0x7f7d0695cdf0>)
[ 0.008827] [00001b3a] libusb: debug [libusb_open] open 1.6
[ 0.008873] [00001b3a] libusb: debug [usbi_add_pollfd] add fd 9 events 4
2021-09-28 12:29:00,311 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration(<usb.backend.libusb1._DeviceHandle object at 0x7f7d06d3beb0>)
[ 0.009020] [00001b3a] libusb: debug [libusb_get_configuration] 
[ 0.009067] [00001b3a] libusb: debug [libusb_get_configuration] active config 1
2021-09-28 12:29:00,311 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7f7d0695cdf0>, 0)
[ 0.009246] [00001b3a] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.009256] [00001b3a] libusb: debug [parse_endpoint] skipping descriptor 24
2021-09-28 12:29:00,312 DEBUG:usb.backend.libusb1:_LibUSB.get_interface_descriptor(<usb.backend.libusb1._Device object at 0x7f7d0695cdf0>, 0, 0, 0)
2021-09-28 12:29:00,312 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7f7d0695cdf0>, 0)
[ 0.009553] [00001b3a] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.009566] [00001b3a] libusb: debug [parse_endpoint] skipping descriptor 24
2021-09-28 12:29:00,312 DEBUG:usb.backend.libusb1:_LibUSB.is_kernel_driver_active(<usb.backend.libusb1._DeviceHandle object at 0x7f7d06d3beb0>, 0)
[ 0.009761] [00001b3a] libusb: debug [libusb_kernel_driver_active] interface 0
False
2021-09-28 12:29:00,312 DEBUG:usb.backend.libusb1:_LibUSB.detach_kernel_driver(<usb.backend.libusb1._DeviceHandle object at 0x7f7d06d3beb0>, 0)
[ 0.009851] [00001b3a] libusb: debug [libusb_detach_kernel_driver] interface 0
Traceback (most recent call last):
  File "test.py", line 20, in <module>
    dev.detach_kernel_driver(intf.bInterfaceNumber)
  File "/usr/local/lib/python3.8/dist-packages/usb/core.py", line 1118, in detach_kernel_driver
    self._ctx.backend.detach_kernel_driver(
  File "/usr/local/lib/python3.8/dist-packages/usb/_debug.py", line 62, in do_trace
    return f(*args, **named_args)
  File "/usr/local/lib/python3.8/dist-packages/usb/backend/libusb1.py", line 920, in detach_kernel_driver
    _check(self.lib.libusb_detach_kernel_driver(dev_handle.handle, intf))
  File "/usr/local/lib/python3.8/dist-packages/usb/backend/libusb1.py", line 604, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 2] Entity not found
2021-09-28 12:29:00,381 DEBUG:usb.backend.libusb1:_LibUSB.close_device(<usb.backend.libusb1._DeviceHandle object at 0x7f7d06d3beb0>)
[ 0.079353] [00001b3a] libusb: debug [libusb_close] 
[ 0.079359] [00001b3a] libusb: debug [usbi_remove_pollfd] remove fd 9
2021-09-28 12:29:00,382 DEBUG:usb.backend.libusb1:_LibUSB._finalize_object()
[ 0.079409] [00001b3a] libusb: debug [libusb_exit] 
[ 0.079411] [00001b3a] libusb: debug [libusb_exit] destroying default context
[ 0.079414] [00001b3a] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.079416] [00001b3a] libusb: debug [handle_events] poll fds modified, reallocating
[ 0.079422] [00001b3a] libusb: debug [handle_events] poll() 2 fds with timeout in 0ms
[ 0.079425] [00001b3a] libusb: debug [handle_events] poll() returned 0
[ 0.079428] [00001b3a] libusb: debug [libusb_unref_device] destroy device 6.1
[ 0.079436] [00001b3a] libusb: debug [libusb_unref_device] destroy device 5.2
[ 0.079439] [00001b3a] libusb: debug [libusb_unref_device] destroy device 5.1
[ 0.079440] [00001b3a] libusb: debug [libusb_unref_device] destroy device 4.1
[ 0.079442] [00001b3a] libusb: debug [libusb_unref_device] destroy device 3.2
[ 0.079444] [00001b3a] libusb: debug [libusb_unref_device] destroy device 3.1
[ 0.079446] [00001b3a] libusb: debug [libusb_unref_device] destroy device 2.1
[ 0.079448] [00001b3a] libusb: debug [libusb_unref_device] destroy device 1.6
[ 0.079450] [00001b3a] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.079452] [00001b3a] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.079453] [00001b3a] libusb: debug [usbi_remove_pollfd] remove fd 6
[ 0.079466] [00001b3a] libusb: debug [usbi_remove_pollfd] remove fd 8
[ 0.079511] [00001b3c] libusb: debug [linux_udev_event_thread_main] udev event thread exiting

This one corresponds to the solution stated here:

2021-09-28 12:34:54,038 DEBUG:usb.backend.libusb1:_LibUSB.__init__(<CDLL 'libusb-1.0.so.0', handle 11d6b00 at 0x7fb41b19aee0>)
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000004] [00001b94] libusb: debug [libusb_init] created default context
[ 0.000018] [00001b94] libusb: debug [libusb_init] libusb v1.0.23.11397
[ 0.000045] [00001b94] libusb: debug [find_usbfs_path] found usbfs at /dev/bus/usb
[ 0.000060] [00001b94] libusb: debug [get_kernel_version] reported kernel version is 5.11.0-36-generic
[ 0.000063] [00001b94] libusb: debug [op_init] bulk continuation flag supported
[ 0.000066] [00001b94] libusb: debug [op_init] zero length packet flag supported
[ 0.000069] [00001b94] libusb: debug [op_init] max iso packet length is (likely) 49152 bytes
[ 0.000084] [00001b94] libusb: debug [op_init] sysfs can relate devices
[ 0.000087] [00001b94] libusb: debug [op_init] sysfs has complete descriptors
[ 0.000469] [00001b96] libusb: debug [linux_udev_event_thread_main] udev event thread entering.
[ 0.004304] [00001b94] libusb: debug [linux_get_device_address] getting address for device: usb1 detached: 0
[ 0.004325] [00001b94] libusb: debug [linux_get_device_address] scan usb1
[ 0.004361] [00001b94] libusb: debug [linux_get_device_address] bus=1 dev=1
[ 0.004367] [00001b94] libusb: debug [linux_enumerate_device] busnum 1 devaddr 1 session_id 257
[ 0.004371] [00001b94] libusb: debug [linux_enumerate_device] allocating new device for 1/1 (session 257)
[ 0.004480] [00001b94] libusb: debug [linux_get_device_address] getting address for device: 1-12 detached: 0
[ 0.004489] [00001b94] libusb: debug [linux_get_device_address] scan 1-12
[ 0.004515] [00001b94] libusb: debug [linux_get_device_address] bus=1 dev=3
[ 0.004518] [00001b94] libusb: debug [linux_enumerate_device] busnum 1 devaddr 3 session_id 259
[ 0.004521] [00001b94] libusb: debug [linux_enumerate_device] allocating new device for 1/3 (session 259)
[ 0.004546] [00001b94] libusb: debug [linux_get_parent_info] Dev 0x11fa470 (1-12) has parent 0x11fa620 (usb1) port 12
[ 0.004630] [00001b94] libusb: debug [linux_get_device_address] getting address for device: 1-4 detached: 0
[ 0.004634] [00001b94] libusb: debug [linux_get_device_address] scan 1-4
[ 0.004663] [00001b94] libusb: debug [linux_get_device_address] bus=1 dev=6
[ 0.004669] [00001b94] libusb: debug [linux_enumerate_device] busnum 1 devaddr 6 session_id 262
[ 0.004672] [00001b94] libusb: debug [linux_enumerate_device] allocating new device for 1/6 (session 262)
[ 0.004699] [00001b94] libusb: debug [linux_get_parent_info] Dev 0x11fa9d0 (1-4) has parent 0x11fa620 (usb1) port 4
[ 0.004778] [00001b94] libusb: debug [linux_get_device_address] getting address for device: usb2 detached: 0
[ 0.004786] [00001b94] libusb: debug [linux_get_device_address] scan usb2
[ 0.004812] [00001b94] libusb: debug [linux_get_device_address] bus=2 dev=1
[ 0.004816] [00001b94] libusb: debug [linux_enumerate_device] busnum 2 devaddr 1 session_id 513
[ 0.004819] [00001b94] libusb: debug [linux_enumerate_device] allocating new device for 2/1 (session 513)
[ 0.004913] [00001b94] libusb: debug [linux_get_device_address] getting address for device: usb3 detached: 0
[ 0.004920] [00001b94] libusb: debug [linux_get_device_address] scan usb3
[ 0.004945] [00001b94] libusb: debug [linux_get_device_address] bus=3 dev=1
[ 0.004948] [00001b94] libusb: debug [linux_enumerate_device] busnum 3 devaddr 1 session_id 769
[ 0.004952] [00001b94] libusb: debug [linux_enumerate_device] allocating new device for 3/1 (session 769)
[ 0.005052] [00001b94] libusb: debug [linux_get_device_address] getting address for device: 3-2 detached: 0
[ 0.005062] [00001b94] libusb: debug [linux_get_device_address] scan 3-2
[ 0.005088] [00001b94] libusb: debug [linux_get_device_address] bus=3 dev=2
[ 0.005095] [00001b94] libusb: debug [linux_enumerate_device] busnum 3 devaddr 2 session_id 770
[ 0.005099] [00001b94] libusb: debug [linux_enumerate_device] allocating new device for 3/2 (session 770)
[ 0.005125] [00001b94] libusb: debug [linux_get_parent_info] Dev 0x11fad40 (3-2) has parent 0x11fac30 (usb3) port 2
[ 0.005199] [00001b94] libusb: debug [linux_get_device_address] getting address for device: usb4 detached: 0
[ 0.005205] [00001b94] libusb: debug [linux_get_device_address] scan usb4
[ 0.005232] [00001b94] libusb: debug [linux_get_device_address] bus=4 dev=1
[ 0.005236] [00001b94] libusb: debug [linux_enumerate_device] busnum 4 devaddr 1 session_id 1025
[ 0.005240] [00001b94] libusb: debug [linux_enumerate_device] allocating new device for 4/1 (session 1025)
[ 0.005325] [00001b94] libusb: debug [linux_get_device_address] getting address for device: usb5 detached: 0
[ 0.005331] [00001b94] libusb: debug [linux_get_device_address] scan usb5
[ 0.005356] [00001b94] libusb: debug [linux_get_device_address] bus=5 dev=1
[ 0.005361] [00001b94] libusb: debug [linux_enumerate_device] busnum 5 devaddr 1 session_id 1281
[ 0.005365] [00001b94] libusb: debug [linux_enumerate_device] allocating new device for 5/1 (session 1281)
[ 0.005456] [00001b94] libusb: debug [linux_get_device_address] getting address for device: 5-1 detached: 0
[ 0.005461] [00001b94] libusb: debug [linux_get_device_address] scan 5-1
[ 0.005487] [00001b94] libusb: debug [linux_get_device_address] bus=5 dev=2
[ 0.005492] [00001b94] libusb: debug [linux_enumerate_device] busnum 5 devaddr 2 session_id 1282
[ 0.005496] [00001b94] libusb: debug [linux_enumerate_device] allocating new device for 5/2 (session 1282)
[ 0.005521] [00001b94] libusb: debug [linux_get_parent_info] Dev 0x11fb0a0 (5-1) has parent 0x11faf90 (usb5) port 1
[ 0.005609] [00001b94] libusb: debug [linux_get_device_address] getting address for device: usb6 detached: 0
[ 0.005616] [00001b94] libusb: debug [linux_get_device_address] scan usb6
[ 0.005642] [00001b94] libusb: debug [linux_get_device_address] bus=6 dev=1
[ 0.005646] [00001b94] libusb: debug [linux_enumerate_device] busnum 6 devaddr 1 session_id 1537
[ 0.005651] [00001b94] libusb: debug [linux_enumerate_device] allocating new device for 6/1 (session 1537)
[ 0.005833] [00001b94] libusb: debug [usbi_add_pollfd] add fd 6 events 1
[ 0.005855] [00001b94] libusb: debug [usbi_io_init] using timerfd for timeouts
[ 0.005859] [00001b94] libusb: debug [usbi_add_pollfd] add fd 8 events 1
2021-09-28 12:34:54,044 INFO:usb.core:find(): using backend "usb.backend.libusb1"
2021-09-28 12:34:54,044 DEBUG:usb.backend.libusb1:_LibUSB.enumerate_devices()
[ 0.006311] [00001b94] libusb: debug [libusb_get_device_list] 
[ 0.006334] [00001b94] libusb: debug [discovered_devs_append] need to increase capacity
2021-09-28 12:34:54,045 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33c10>)
[ 0.006574] [00001b94] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:34:54,045 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33dc0>)
[ 0.006844] [00001b94] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:34:54,045 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33ca0>)
[ 0.007084] [00001b94] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:34:54,045 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33e20>)
[ 0.007288] [00001b94] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:34:54,046 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33d30>)
[ 0.007487] [00001b94] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:34:54,046 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33e80>)
[ 0.007679] [00001b94] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:34:54,046 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33c70>)
[ 0.007866] [00001b94] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:34:54,046 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>)
[ 0.008066] [00001b94] libusb: debug [libusb_get_device_descriptor] 
2021-09-28 12:34:54,046 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 0)
[ 0.008215] [00001b94] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.008225] [00001b94] libusb: debug [parse_endpoint] skipping descriptor 24
2021-09-28 12:34:54,047 DEBUG:usb.backend.libusb1:_LibUSB.get_interface_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 0, 0, 0)
2021-09-28 12:34:54,047 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 0)
[ 0.008508] [00001b94] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.008520] [00001b94] libusb: debug [parse_endpoint] skipping descriptor 24
2021-09-28 12:34:54,047 DEBUG:usb.backend.libusb1:_LibUSB.open_device(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>)
[ 0.008748] [00001b94] libusb: debug [libusb_open] open 1.6
[ 0.008793] [00001b94] libusb: debug [usbi_add_pollfd] add fd 9 events 4
2021-09-28 12:34:54,047 DEBUG:usb.backend.libusb1:_LibUSB.is_kernel_driver_active(<usb.backend.libusb1._DeviceHandle object at 0x7fb41ae33c10>, 0)
[ 0.008957] [00001b94] libusb: debug [libusb_kernel_driver_active] interface 0
2021-09-28 12:34:54,047 DEBUG:usb.backend.libusb1:_LibUSB.get_interface_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 0, 1, 0)
2021-09-28 12:34:54,047 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 0)
[ 0.009149] [00001b94] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.009159] [00001b94] libusb: debug [parse_endpoint] skipping descriptor 24
2021-09-28 12:34:54,048 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 1)
[ 0.009283] [00001b94] libusb: debug [libusb_get_config_descriptor] index 1
[ 0.009291] [00001b94] libusb: debug [parse_endpoint] skipping descriptor 24
[ 0.009294] [00001b94] libusb: debug [parse_endpoint] skipping descriptor b
2021-09-28 12:34:54,048 DEBUG:usb.backend.libusb1:_LibUSB.get_interface_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 0, 0, 1)
2021-09-28 12:34:54,048 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 1)
[ 0.009460] [00001b94] libusb: debug [libusb_get_config_descriptor] index 1
[ 0.009467] [00001b94] libusb: debug [parse_endpoint] skipping descriptor 24
[ 0.009471] [00001b94] libusb: debug [parse_endpoint] skipping descriptor b
2021-09-28 12:34:54,048 DEBUG:usb.backend.libusb1:_LibUSB.is_kernel_driver_active(<usb.backend.libusb1._DeviceHandle object at 0x7fb41ae33c10>, 0)
[ 0.009589] [00001b94] libusb: debug [libusb_kernel_driver_active] interface 0
2021-09-28 12:34:54,048 DEBUG:usb.backend.libusb1:_LibUSB.get_interface_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 0, 1, 1)
2021-09-28 12:34:54,048 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 1)
[ 0.009705] [00001b94] libusb: debug [libusb_get_config_descriptor] index 1
[ 0.009713] [00001b94] libusb: debug [parse_endpoint] skipping descriptor 24
[ 0.009716] [00001b94] libusb: debug [parse_endpoint] skipping descriptor b
2021-09-28 12:34:54,048 DEBUG:usb.backend.libusb1:_LibUSB.get_interface_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 1, 0, 1)
2021-09-28 12:34:54,048 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 1)
[ 0.009866] [00001b94] libusb: debug [libusb_get_config_descriptor] index 1
[ 0.009873] [00001b94] libusb: debug [parse_endpoint] skipping descriptor 24
[ 0.009876] [00001b94] libusb: debug [parse_endpoint] skipping descriptor b
2021-09-28 12:34:54,048 DEBUG:usb.backend.libusb1:_LibUSB.is_kernel_driver_active(<usb.backend.libusb1._DeviceHandle object at 0x7fb41ae33c10>, 1)
[ 0.009989] [00001b94] libusb: debug [libusb_kernel_driver_active] interface 1
2021-09-28 12:34:54,048 DEBUG:usb.backend.libusb1:_LibUSB.get_interface_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 1, 1, 1)
2021-09-28 12:34:54,048 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 1)
[ 0.010102] [00001b94] libusb: debug [libusb_get_config_descriptor] index 1
[ 0.010109] [00001b94] libusb: debug [parse_endpoint] skipping descriptor 24
[ 0.010113] [00001b94] libusb: debug [parse_endpoint] skipping descriptor b
2021-09-28 12:34:54,048 DEBUG:usb.backend.libusb1:_LibUSB.get_interface_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 2, 0, 1)
2021-09-28 12:34:54,049 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 1)
[ 0.010309] [00001b94] libusb: debug [libusb_get_config_descriptor] index 1
[ 0.010322] [00001b94] libusb: debug [parse_endpoint] skipping descriptor 24
[ 0.010325] [00001b94] libusb: debug [parse_endpoint] skipping descriptor b
2021-09-28 12:34:54,049 DEBUG:usb.backend.libusb1:_LibUSB.is_kernel_driver_active(<usb.backend.libusb1._DeviceHandle object at 0x7fb41ae33c10>, 2)
[ 0.010510] [00001b94] libusb: debug [libusb_kernel_driver_active] interface 2
2021-09-28 12:34:54,049 DEBUG:usb.backend.libusb1:_LibUSB.get_interface_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 2, 1, 1)
2021-09-28 12:34:54,049 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 1)
[ 0.010704] [00001b94] libusb: debug [libusb_get_config_descriptor] index 1
[ 0.010717] [00001b94] libusb: debug [parse_endpoint] skipping descriptor 24
[ 0.010720] [00001b94] libusb: debug [parse_endpoint] skipping descriptor b
2021-09-28 12:34:54,049 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 0)
[ 0.010912] [00001b94] libusb: debug [libusb_get_config_descriptor] index 0
[ 0.010919] [00001b94] libusb: debug [parse_endpoint] skipping descriptor 24
2021-09-28 12:34:54,049 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7fb41ae33df0>, 1)
[ 0.011086] [00001b94] libusb: debug [libusb_get_config_descriptor] index 1
[ 0.011097] [00001b94] libusb: debug [parse_endpoint] skipping descriptor 24
[ 0.011100] [00001b94] libusb: debug [parse_endpoint] skipping descriptor b
2021-09-28 12:34:54,050 DEBUG:usb.backend.libusb1:_LibUSB.set_configuration(<usb.backend.libusb1._DeviceHandle object at 0x7fb41ae33c10>, 2)
[ 0.011298] [00001b94] libusb: debug [libusb_set_configuration] configuration 2
Traceback (most recent call last):
  File "test.py", line 22, in <module>
    dev.set_configuration(2)
  File "/usr/local/lib/python3.8/dist-packages/usb/core.py", line 912, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "/usr/local/lib/python3.8/dist-packages/usb/core.py", line 113, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/usb/core.py", line 159, in managed_set_configuration
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
  File "/usr/local/lib/python3.8/dist-packages/usb/_debug.py", line 62, in do_trace
    return f(*args, **named_args)
  File "/usr/local/lib/python3.8/dist-packages/usb/backend/libusb1.py", line 812, in set_configuration
    _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
  File "/usr/local/lib/python3.8/dist-packages/usb/backend/libusb1.py", line 604, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 16] Resource busy
2021-09-28 12:34:54,113 DEBUG:usb.backend.libusb1:_LibUSB.close_device(<usb.backend.libusb1._DeviceHandle object at 0x7fb41ae33c10>)
[ 0.074599] [00001b94] libusb: debug [libusb_close] 
[ 0.074606] [00001b94] libusb: debug [usbi_remove_pollfd] remove fd 9
2021-09-28 12:34:54,113 DEBUG:usb.backend.libusb1:_LibUSB._finalize_object()
[ 0.074737] [00001b94] libusb: debug [libusb_exit] 
[ 0.074742] [00001b94] libusb: debug [libusb_exit] destroying default context
[ 0.074745] [00001b94] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.074747] [00001b94] libusb: debug [handle_events] poll fds modified, reallocating
[ 0.074753] [00001b94] libusb: debug [handle_events] poll() 2 fds with timeout in 0ms
[ 0.074756] [00001b94] libusb: debug [handle_events] poll() returned 0
[ 0.074759] [00001b94] libusb: debug [libusb_unref_device] destroy device 6.1
[ 0.074761] [00001b94] libusb: debug [libusb_unref_device] destroy device 5.2
[ 0.074762] [00001b94] libusb: debug [libusb_unref_device] destroy device 5.1
[ 0.074764] [00001b94] libusb: debug [libusb_unref_device] destroy device 4.1
[ 0.074765] [00001b94] libusb: debug [libusb_unref_device] destroy device 3.2
[ 0.074766] [00001b94] libusb: debug [libusb_unref_device] destroy device 3.1
[ 0.074768] [00001b94] libusb: debug [libusb_unref_device] destroy device 2.1
[ 0.074770] [00001b94] libusb: debug [libusb_unref_device] destroy device 1.6
[ 0.074771] [00001b94] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.074773] [00001b94] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.074774] [00001b94] libusb: debug [usbi_remove_pollfd] remove fd 6
[ 0.074790] [00001b94] libusb: debug [usbi_remove_pollfd] remove fd 8
[ 0.074850] [00001b96] libusb: debug [linux_udev_event_thread_main] udev event thread exiting

Personally I couldn’t find anything of relative importance in these logs. I’d be glad if someone saw something I missed. Nevertheless, I also tried to manually unbind the usbfs module stated in the previous dmesg logs without luck. Unmounting the device or manually unbinding it from /sys/bus/usb/drivers/usb/ was also futile. I blacklisted a bunch of kernel modules as well, but again, it didn’t work.

Curiously enough, I tested a similar C script that worked flawlessly with no errors and switched configurations as desired. Nevertheless, I really want to keep using Python for my personal project.

EDIT: Yes, I tried using sudo and executing as root. No luck.

If you have any ideas about this I’d be glad to hear them.

Linux v-HP-Desktop-M01-F1xxx 5.11.0-36-generic #40~20.04.1-Ubuntu SMP Sat Sep 18 02:14:19 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jonasmalacofilhocommented, Sep 29, 2021

I also tried to use usb_modeswitch -v dead -p beef -d and usb_modeswitch -v dead -p beef -u 2 to try and detach/swap configs respectively but it gives me, yet again, a resource busy error.

usb_modeswitch uses libusb as well (from C) so this problem doesn’t appear to be specific to PyUSB.

[…] on an Arch machine and all of them worked flawlessly. It looks like a weird bug in the library or kernel shenanigans.

Agreed.

I’m not closing down the issue just in case you require more logs or snippets.

Since it doesn’t appear to be specific to PyUSB, and we also don’t have a good way to debug this, I think I’m going to close the issue.

0reactions
tronchamacommented, Sep 30, 2021

@mcuee

  1. Force using the legacy libusb-0.1 backend with pyusb. This may or may not work.

I tried and it didn’t work, sadly.

  1. You are using libusb-1.0.23, maybe you want tp upgrade libusb to 1.0.24 or even latest git to see if that helps.

Will definitely try this out, thanks a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I keep getting "usb.core.USBError: [Errno 16] Resource ...
python - I keep getting "usb. core. USBError: [Errno 16] Resource busy" when trying to read from a USB device using pyusb -...
Read more >
Can't upload any sketch using visual code (Errno 16) ...
I just cant upload any sketch (VS code, Mac OS). I've tried normal upload and verbose, changing ports, reboots, rebuilds, terminal command ...
Read more >
I Keep Getting "Usb.Core.Usberror: [Errno 16] Resource ...
I'm always getting this error and no solution worked for me : My software: Python 2.7.8 Can't change configuration: [Errno 16] Resource busy...
Read more >
Device or resource busy/ file is locked error when making ...
Device or resource busy/ file is locked error when making changes to ... On the vSphere Client, select the host and click the...
Read more >
What is error "IOError: [Errno 16] Device or resource busy"?
It means that your software can't access it because something else is, or has claimed it. It's not always fully accurate. It really...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found