From c86d4be0fe9742c3e3b28c0eb626bf1b0e97cf29 Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Mon, 8 May 2023 11:23:00 -0400 Subject: [PATCH] hidapi: retry open several times with short wait to allow for delay in setting up permissions --- lib/hidapi/udev.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/hidapi/udev.py b/lib/hidapi/udev.py index afb69ac6..d94de66c 100644 --- a/lib/hidapi/udev.py +++ b/lib/hidapi/udev.py @@ -322,7 +322,19 @@ def open_path(device_path): """ assert device_path assert device_path.startswith('/dev/hidraw') - return _os.open(device_path, _os.O_RDWR | _os.O_SYNC) + + _log.info('OPEN PATH %s', device_path) + retrycount = 0 + while (retrycount < 3): + retrycount += 1 + try: + return _os.open(device_path, _os.O_RDWR | _os.O_SYNC) + except OSError as e: + _log.info('OPEN PATH FAILED %s ERROR %s %s', device_path, e.errno, e) + if e.errno == _errno.EACCES: + sleep(0.1) + else: + raise def close(device_handle):