Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PermissionError when reconnecting mtdev input devices (kivy#7587)
The Linux kernel creates input devices then hands permission management off to udev. This results in a period of time when the device exists, but is readable only by root. The MTDMotionEventProvider handles reconnects by spinning in a loop waiting for the device to reappear. As soon as the device reappears, the provider immediately attempts to create a new mtdev Device. This happens faster than udev can update the file permissions so the Device construction fails raising an error causing no further reconnects to be attempted. This patch adds some spinning code to the Device object to re-try opening the device file for a period of time if a PermissionError was received. The retries will be applied on initial connection to the MT device (in case the device happened to be newly attached just as the application was starting) as well as reconnection attempts. Attempts are time-limited so that real system configuration errors will still be detected, but long enough of a duration that any reasonable system should have enough time for udev to fix the permissions. For reference, a Raspberry Pi 4 (a small single-board computer) takes about 0.6s between creating the file and fixing the permissions.
- Loading branch information