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.

Resource busy during set_configuration or write

See original GitHub issue

With the following script, I got Resource busy error.

import usb.core
import usb.util


print('r311 usb testing start')
dev = usb.core.find(idVendor=0x2109, idProduct=0x7638)
pkt_pwd_check = b'\xef\x01\xff\xff\xff\xff\x01\x00\x07\x13\x00\x00\x00\x00\x00\x1b'


dev.set_configuration()
cfg = dev.get_active_configuration()
print(f'config: {cfg}')

# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]


ep = usb.util.find_descriptor(
    intf,
    # match the first OUT endpoint
    custom_match = \
    lambda e: \
        usb.util.endpoint_direction(e.bEndpointAddress) == \
        usb.util.ENDPOINT_OUT)

assert ep is not None

# write the data
ep.write(pkt_pwd_check)
LIBUSB_DEBUG=4 PYUSB_DEBUG=debug python r311-reader-usb.py
r311 usb testing start
2021-02-10 11:55:13,196 DEBUG:usb.backend.libusb1:_LibUSB.__init__(<CDLL 'libusb-1.0.so.0', handle 557ad14f2e10 at 0x7f139d8e36d0>)
[timestamp] [threadID] facility level [function call] <message>
--------------------------------------------------------------------------------
[ 0.000013] [00003411] libusb: debug [libusb_init] created default context
[ 0.000028] [00003411] libusb: debug [libusb_init] libusb v1.0.24.11584
[ 0.000036] [00003411] libusb: debug [get_kernel_version] reported kernel version is 5.4.91-1-lts
[ 0.000059] [00003411] libusb: debug [op_init] found usbfs at /dev/bus/usb
[ 0.000064] [00003411] libusb: debug [op_init] max iso packet length is (likely) 98304 bytes
[ 0.000080] [00003411] libusb: debug [op_init] sysfs is available
[ 0.000643] [00003413] libusb: debug [linux_udev_event_thread_main] udev event thread entering
[ 0.004368] [00003411] libusb: debug [linux_get_device_address] getting address for device: usb1 detached: 0
[ 0.004382] [00003411] libusb: debug [linux_get_device_address] scan usb1
[ 0.004412] [00003411] libusb: debug [linux_get_device_address] bus=1 dev=1
[ 0.004417] [00003411] libusb: debug [linux_enumerate_device] busnum 1 devaddr 1 session_id 257
[ 0.004422] [00003411] libusb: debug [linux_enumerate_device] allocating new device for 1/1 (session 257)
[ 0.004529] [00003411] libusb: debug [linux_get_device_address] getting address for device: 1-1 detached: 0
[ 0.004536] [00003411] libusb: debug [linux_get_device_address] scan 1-1
[ 0.004563] [00003411] libusb: debug [linux_get_device_address] bus=1 dev=16
[ 0.004568] [00003411] libusb: debug [linux_enumerate_device] busnum 1 devaddr 16 session_id 272
[ 0.004573] [00003411] libusb: debug [linux_enumerate_device] allocating new device for 1/16 (session 272)
[ 0.004601] [00003411] libusb: debug [linux_get_parent_info] dev 0x557ad1512460 (1-1) has parent 0x557ad1511cd0 (usb1) port 1
[ 0.004685] [00003411] libusb: debug [linux_get_device_address] getting address for device: 1-2 detached: 0
[ 0.004691] [00003411] libusb: debug [linux_get_device_address] scan 1-2
[ 0.004717] [00003411] libusb: debug [linux_get_device_address] bus=1 dev=2
[ 0.004722] [00003411] libusb: debug [linux_enumerate_device] busnum 1 devaddr 2 session_id 258
[ 0.004727] [00003411] libusb: debug [linux_enumerate_device] allocating new device for 1/2 (session 258)
[ 0.004754] [00003411] libusb: debug [linux_get_parent_info] dev 0x557ad15125d0 (1-2) has parent 0x557ad1511cd0 (usb1) port 2
[ 0.004842] [00003411] libusb: debug [linux_get_device_address] getting address for device: 1-2.3 detached: 0
[ 0.004848] [00003411] libusb: debug [linux_get_device_address] scan 1-2.3
[ 0.004876] [00003411] libusb: debug [linux_get_device_address] bus=1 dev=4
[ 0.004881] [00003411] libusb: debug [linux_enumerate_device] busnum 1 devaddr 4 session_id 260
[ 0.004886] [00003411] libusb: debug [linux_enumerate_device] allocating new device for 1/4 (session 260)
[ 0.004913] [00003411] libusb: debug [linux_get_parent_info] dev 0x557ad14f7610 (1-2.3) has parent 0x557ad15125d0 (1-2) port 3
[ 0.004997] [00003411] libusb: debug [linux_get_device_address] getting address for device: 1-2.4 detached: 0
[ 0.005003] [00003411] libusb: debug [linux_get_device_address] scan 1-2.4
[ 0.005031] [00003411] libusb: debug [linux_get_device_address] bus=1 dev=9
[ 0.005036] [00003411] libusb: debug [linux_enumerate_device] busnum 1 devaddr 9 session_id 265
[ 0.005039] [00003411] libusb: debug [linux_enumerate_device] allocating new device for 1/9 (session 265)
[ 0.005067] [00003411] libusb: debug [linux_get_parent_info] dev 0x557ad14f7720 (1-2.4) has parent 0x557ad15125d0 (1-2) port 4
[ 0.005149] [00003411] libusb: debug [linux_get_device_address] getting address for device: 1-3 detached: 0
[ 0.005156] [00003411] libusb: debug [linux_get_device_address] scan 1-3
[ 0.005183] [00003411] libusb: debug [linux_get_device_address] bus=1 dev=3
[ 0.005188] [00003411] libusb: debug [linux_enumerate_device] busnum 1 devaddr 3 session_id 259
[ 0.005193] [00003411] libusb: debug [linux_enumerate_device] allocating new device for 1/3 (session 259)
[ 0.005220] [00003411] libusb: debug [linux_get_parent_info] dev 0x557ad15126c0 (1-3) has parent 0x557ad1511cd0 (usb1) port 3
[ 0.005302] [00003411] libusb: debug [linux_get_device_address] getting address for device: 1-5 detached: 0
[ 0.005308] [00003411] libusb: debug [linux_get_device_address] scan 1-5
[ 0.005335] [00003411] libusb: debug [linux_get_device_address] bus=1 dev=5
[ 0.005340] [00003411] libusb: debug [linux_enumerate_device] busnum 1 devaddr 5 session_id 261
[ 0.005344] [00003411] libusb: debug [linux_enumerate_device] allocating new device for 1/5 (session 261)
[ 0.005374] [00003411] libusb: debug [linux_get_parent_info] dev 0x557ad14f7940 (1-5) has parent 0x557ad1511cd0 (usb1) port 5
[ 0.005462] [00003411] libusb: debug [linux_get_device_address] getting address for device: usb2 detached: 0
[ 0.005470] [00003411] libusb: debug [linux_get_device_address] scan usb2
[ 0.005495] [00003411] libusb: debug [linux_get_device_address] bus=2 dev=1
[ 0.005500] [00003411] libusb: debug [linux_enumerate_device] busnum 2 devaddr 1 session_id 513
[ 0.005505] [00003411] libusb: debug [linux_enumerate_device] allocating new device for 2/1 (session 513)
[ 0.005616] [00003411] libusb: debug [linux_get_device_address] getting address for device: 2-2 detached: 0
[ 0.005622] [00003411] libusb: debug [linux_get_device_address] scan 2-2
[ 0.005648] [00003411] libusb: debug [linux_get_device_address] bus=2 dev=2
[ 0.005653] [00003411] libusb: debug [linux_enumerate_device] busnum 2 devaddr 2 session_id 514
[ 0.005658] [00003411] libusb: debug [linux_enumerate_device] allocating new device for 2/2 (session 514)
[ 0.005684] [00003411] libusb: debug [linux_get_parent_info] dev 0x557ad14f7eb0 (2-2) has parent 0x557ad14f7fb0 (usb2) port 2
[ 0.005790] [00003411] libusb: debug [usbi_add_event_source] add fd 5 events 1
[ 0.005799] [00003411] libusb: debug [usbi_io_init] using timer for timeouts
[ 0.005803] [00003411] libusb: debug [usbi_add_event_source] add fd 6 events 1
2021-02-10 11:55:13,202 INFO:usb.core:find(): using backend "usb.backend.libusb1"
2021-02-10 11:55:13,203 DEBUG:usb.backend.libusb1:_LibUSB.enumerate_devices()
[ 0.006279] [00003411] libusb: debug [libusb_get_device_list]  
[ 0.006292] [00003411] libusb: debug [discovered_devs_append] need to increase capacity
2021-02-10 11:55:13,203 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f139d6b2c70>)
[ 0.006463] [00003411] libusb: debug [libusb_get_device_descriptor]  
2021-02-10 11:55:13,203 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f139d6b2e50>)
[ 0.006701] [00003411] libusb: debug [libusb_get_device_descriptor]  
2021-02-10 11:55:13,203 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f139d6b2d00>)
[ 0.006897] [00003411] libusb: debug [libusb_get_device_descriptor]  
2021-02-10 11:55:13,203 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f139d6b2eb0>)
[ 0.007059] [00003411] libusb: debug [libusb_get_device_descriptor]  
2021-02-10 11:55:13,204 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f139d6b2d90>)
[ 0.007646] [00003411] libusb: debug [libusb_get_device_descriptor]  
2021-02-10 11:55:13,205 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f139d6b2f10>)
[ 0.008708] [00003411] libusb: debug [libusb_get_device_descriptor]  
2021-02-10 11:55:13,205 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f139d6b2cd0>)
[ 0.009045] [00003411] libusb: debug [libusb_get_device_descriptor]  
2021-02-10 11:55:13,206 DEBUG:usb.backend.libusb1:_LibUSB.get_device_descriptor(<usb.backend.libusb1._Device object at 0x7f139d6b2e80>)
[ 0.009269] [00003411] libusb: debug [libusb_get_device_descriptor]  
2021-02-10 11:55:13,206 DEBUG:usb.backend.libusb1:_LibUSB.get_configuration_descriptor(<usb.backend.libusb1._Device object at 0x7f139d6b2e80>, 0)
[ 0.010412] [00003411] libusb: debug [libusb_get_config_descriptor] index 0
2021-02-10 11:55:13,207 DEBUG:usb.backend.libusb1:_LibUSB.open_device(<usb.backend.libusb1._Device object at 0x7f139d6b2e80>)
[ 0.011416] [00003411] libusb: debug [libusb_open] open 1.16
[ 0.011523] [00003411] libusb: debug [usbi_add_event_source] add fd 7 events 4
2021-02-10 11:55:13,208 DEBUG:usb.backend.libusb1:_LibUSB.set_configuration(<usb.backend.libusb1._DeviceHandle object at 0x7f139da4e5e0>, 1)
[ 0.012038] [00003411] libusb: debug [libusb_set_configuration] configuration 1
Traceback (most recent call last):
  File "/opt/garfield/projects/fingerprint/fingerprint-r311/r311-reader-usb.py", line 10, in <module>
    dev.set_configuration()
  File "/home/garfield/.local/lib/python3.9/site-packages/usb/core.py", line 905, in set_configuration
    self._ctx.managed_set_configuration(self, configuration)
  File "/home/garfield/.local/lib/python3.9/site-packages/usb/core.py", line 113, in wrapper
    return f(self, *args, **kwargs)
  File "/home/garfield/.local/lib/python3.9/site-packages/usb/core.py", line 159, in managed_set_configuration
    self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
  File "/home/garfield/.local/lib/python3.9/site-packages/usb/_debug.py", line 62, in do_trace
    return f(*args, **named_args)
  File "/home/garfield/.local/lib/python3.9/site-packages/usb/backend/libusb1.py", line 812, in set_configuration
    _check(self.lib.libusb_set_configuration(dev_handle.handle, config_value))
  File "/home/garfield/.local/lib/python3.9/site-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-02-10 11:55:13,211 DEBUG:usb.backend.libusb1:_LibUSB.close_device(<usb.backend.libusb1._DeviceHandle object at 0x7f139da4e5e0>)
[ 0.014534] [00003411] libusb: debug [libusb_close]  
[ 0.014545] [00003411] libusb: debug [usbi_remove_event_source] remove fd 7
2021-02-10 11:55:13,211 DEBUG:usb.backend.libusb1:_LibUSB._finalize_object()
[ 0.014676] [00003411] libusb: debug [libusb_exit]  
[ 0.014682] [00003411] libusb: debug [libusb_exit] destroying default context
[ 0.014688] [00003411] libusb: debug [libusb_handle_events_timeout_completed] doing our own event handling
[ 0.014693] [00003411] libusb: debug [handle_events] event sources modified, reallocating event data
[ 0.014701] [00003411] libusb: debug [usbi_wait_for_events] poll() 2 fds with timeout in 0ms
[ 0.014708] [00003411] libusb: debug [usbi_wait_for_events] poll() returned 0
[ 0.014714] [00003411] libusb: debug [libusb_unref_device] destroy device 2.2
[ 0.014719] [00003411] libusb: debug [libusb_unref_device] destroy device 2.1
[ 0.014724] [00003411] libusb: debug [libusb_unref_device] destroy device 1.5
[ 0.014729] [00003411] libusb: debug [libusb_unref_device] destroy device 1.3
[ 0.014734] [00003411] libusb: debug [libusb_unref_device] destroy device 1.9
[ 0.014738] [00003411] libusb: debug [libusb_unref_device] destroy device 1.4
[ 0.014743] [00003411] libusb: debug [libusb_unref_device] destroy device 1.2
[ 0.014748] [00003411] libusb: debug [libusb_unref_device] destroy device 1.16
[ 0.014753] [00003411] libusb: debug [libusb_unref_device] destroy device 1.1
[ 0.014758] [00003411] libusb: debug [usbi_remove_event_source] remove fd 6
[ 0.014768] [00003411] libusb: debug [usbi_remove_event_source] remove fd 5
[ 0.014790] [00003413] libusb: debug [linux_udev_event_thread_main] udev event thread exiting

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jonasmalacofilhocommented, Feb 10, 2021

According to the libusb documentation for libusb_set_configuration:

Returns

  • […]
  • LIBUSB_ERROR_BUSY if interfaces are currently claimed
  • […]

See also:

0reactions
jonasmalacofilhocommented, Feb 11, 2021

Thanks, @mcuee!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Errno 16] Resource busy · Issue #76 - GitHub
I'm working on Arch Linux Arm (Raspberry Pi model B) ... no kernel driver attached claimed device Could not set configuration: [Errno 16]...
Read more >
LibUSB ErrNo 16 Resource Busy - Magstripe reader
When executed as root, I get a Resource busy on the call to self._device.set_configuration() . I have run all the updates and I...
Read more >
avrdude: usbdev_open(): WARNING: failed to set configuration 1
hello, Upload message: "avrdude: usbdev_open(): WARNING: failed to set configuration 1: Device or resource busy " I can't upload my programm ...
Read more >
ORA-00054: resource busy and acquire with NOWAIT ...
Another solution in Oracle 11g is to create a timeout to set how long you want DDL to wait for the object to...
Read more >
Controlling An Arduino From A Raspberry Pi
Learn how to communicate with and control an Arduino Uno directly from a Raspberry Pi over the USB port to extend functionality of...
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