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

Issue Connecting to Joystick after Reboot #142

Open SirPingsAlot opened 4 years ago

SirPingsAlot commented 4 years ago

I have a fully working application which is running on a Raspberry Pi4 in Python 3.7.3. I have installed the latest version of evdev which I believe is 1.3.0.

My application includes a GUI written in TKinter and I have setup the app to auto start using systemd to fire up the X window manager and start my application. I have setup a udev rule to auto create a symlink at '/dev/LogitechJoyStick' any time the joystick is plugged in which works perfect. Systemd is verifying that the joystick symlink exists prior to starting the application so I know the device is available when the application starts.

When my app runs the InputDevice() function I get the following error:

Exception ignored in: <function InputDevice.del at 0xb60bd858> Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/evdev/device.py", line 159, in del self.close() File "/usr/local/lib/python3.7/dist-packages/evdev/device.py", line 304, in close super().close() File "/usr/local/lib/python3.7/dist-packages/evdev/eventio_async.py", line 54, in close loop = asyncio.get_event_loop() File "/usr/lib/python3.7/asyncio/events.py", line 644, in get_event_loop % threading.current_thread().name) RuntimeError: There is no current event loop in thread 't3'.

If I simply unplug the device and plug it back in, the app instantly connects and the joystick starts working. I have traced this down to line 133 in 'device.py'.

    info_res = _input.ioctl_devinfo(self.fd)

If I run the following commands from a python window I can recreate the error: (omitting imports)

joy='/dev/LogitechJoyStick' fd = os.open(joy, os.O_RDWR | os. O_NONBLOCK) "Outputs an increasing number with each iteration, ie. 6"

_input.ioctl_devinfo(fd) "Generates the following error"

Traceback (most recent call last): File "<pyshell#7>", line 1, in info_res = _input.ioctl_devinfo(fd) OSError: [Errno 22] Invalid argument

I have not been able to trace the problem any further but it seems to be getting a file descriptor from os.open() which tells me the problem lies somewhere down the line. I believe this issue is related to other open issues such as #134 and #120.

Any help with this is much appreciated!