gvalkov / python-evdev

Python bindings for the Linux input subsystem
https://python-evdev.rtfd.org/
BSD 3-Clause "New" or "Revised" License
334 stars 112 forks source link

InputDevice destructor blocks #144

Closed sezanzeb closed 2 years ago

sezanzeb commented 3 years ago
#!/usr/bin/python3
import evdev

def a():
    print([evdev.InputDevice(path) for path in evdev.list_devices()])

a()
print('end')

Various InputDevice objects are printed immediately, but it takes a second until 'end' appears because function a seems to be exited with a delay. If you multiply list_devices() the delay becomes longer.

It seems very odd that a function that prints the result then takes additional time to exit, seemingly doing nothing at all. Is there some blocking stuff in InputDevice destructors going on? It seems the delay happens as soon as the InputDevice objects are not needed anymore.

sezanzeb commented 3 years ago

It's https://github.com/gvalkov/python-evdev/blob/862c4111e6adfe316d2d1c8222507f41f9d1e75e/evdev/device.py#L305 that takes the time