Wait until the joystick device is readable after it appears to prevent race conditions where jstest fails with temporary "permission denied" errors

This commit is contained in:
Fabio Manganiello 2021-05-16 00:26:28 +02:00
parent def8c0dd76
commit d7d5bcdd0c
1 changed files with 10 additions and 4 deletions

View File

@ -100,11 +100,17 @@ class JoystickJstestBackend(Backend):
def _wait_ready(self):
self.logger.info(f'Waiting for joystick device on {self.device}')
while not self.should_stop() and not os.path.exists(self.device):
time.sleep(1)
while not self.should_stop():
if not os.path.exists(self.device):
time.sleep(1)
if self.should_stop():
return
try:
with open(self.device, 'rb'):
break
except Exception as e:
self.logger.debug(e)
time.sleep(0.1)
continue
self.bus.post(JoystickConnectedEvent(device=self.device))