From d7d5bcdd0c8c55c92e86191c3bb957d2c1ec01f1 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 16 May 2021 00:26:28 +0200 Subject: [PATCH] Wait until the joystick device is readable after it appears to prevent race conditions where jstest fails with temporary "permission denied" errors --- platypush/backend/joystick/jstest.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/platypush/backend/joystick/jstest.py b/platypush/backend/joystick/jstest.py index 5a78e8985c..7ec8744379 100644 --- a/platypush/backend/joystick/jstest.py +++ b/platypush/backend/joystick/jstest.py @@ -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))