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

View file

@ -100,11 +100,17 @@ class JoystickJstestBackend(Backend):
def _wait_ready(self): def _wait_ready(self):
self.logger.info(f'Waiting for joystick device on {self.device}') self.logger.info(f'Waiting for joystick device on {self.device}')
while not self.should_stop() and not os.path.exists(self.device): while not self.should_stop():
time.sleep(1) if not os.path.exists(self.device):
time.sleep(1)
if self.should_stop(): try:
return 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)) self.bus.post(JoystickConnectedEvent(device=self.device))