Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait up to two seconds for input device to become available. #215

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions evdev/uinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,20 @@ def _find_device_linux(self, sysname):
# It is possible that there is some delay before /dev/input/event* shows
# up on old systems that do not use devtmpfs, so if the device cannot be
# found, wait for a short amount and then try again once.
try:
return device.InputDevice(device_path)
except FileNotFoundError:
time.sleep(0.1)
return device.InputDevice(device_path)
#
# Furthermore, even if devtmpfs is in use, it is possible that the device
# does show up immediately, but without the correct permissions that
# still need to be set by udev. Wait for up to two seconds for either the
# device to show up or the permissions to be set.
for attempt in range(19):
try:
return device.InputDevice(device_path)
except (FileNotFoundError, PermissionError):
time.sleep(0.1)

# Last attempt. If this fails, whatever exception the last attempt raises
# shall be the exception that this function raises.
return device.InputDevice(device_path)

def _find_device_fallback(self):
"""
Expand Down