From fc794d0fac0a6846802a7b29eb89586e459e0866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Troels=20Irgens-M=C3=B8ller?= Date: Wed, 26 Apr 2017 11:32:03 +0000 Subject: [PATCH] Retry _configure_option to fix IOError caused by not-ready sys files --- requirements.txt | 1 + setup.py | 2 +- txgpio/sysfs.py | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 3eb29f0..9a8cab1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ twisted +retry diff --git a/setup.py b/setup.py index 03fa582..0e68848 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ version=txgpio.__version__, description='Twisted-based asynchronous library for using GPIO.', packages=find_packages(), - install_requires=['twisted'], + install_requires=['twisted', 'retry'], py_modules=['txgpio'], license="MIT", ) diff --git a/txgpio/sysfs.py b/txgpio/sysfs.py index 443897b..3302114 100644 --- a/txgpio/sysfs.py +++ b/txgpio/sysfs.py @@ -1,5 +1,6 @@ import os.path import platform +from retry import retry from twisted.python import log try: platform.linux_distribution() @@ -102,6 +103,7 @@ def _open_gpio_node(self): gpio_value_path = os.path.join(self.sysfs_gpio_node_dir, 'value') return open(gpio_value_path, mode) + @retry(IOError, tries=3, delay=0.02, backoff=5) def _configure_option(self, gpio_dir, variable, value, options): if value is not None: value = value.lower()