Skip to content

Commit f0cb7da

Browse files
authored
Merge pull request #1704 from QSchulz/dev/GpioDigitalOutput-fix-no-attr-on-exception
agents/sysfsgpio: fix misleading Python error when permission denied
2 parents e5d537c + e1df6c1 commit f0cb7da

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

labgrid/util/agents/sysfsgpio.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def _assert_gpio_line_is_exported(index):
2424
raise ValueError("Device not found")
2525

2626
def __init__(self, index):
27+
self.gpio_sysfs_value_fd = None
2728
self._logger = logging.getLogger("Device: ")
2829
GpioDigitalOutput._assert_gpio_line_is_exported(index)
2930
gpio_sysfs_path = os.path.join(GpioDigitalOutput._gpio_sysfs_path_prefix,
@@ -41,7 +42,8 @@ def __init__(self, index):
4142
self.gpio_sysfs_value_fd = os.open(gpio_sysfs_value_path, flags=(os.O_RDWR | os.O_SYNC))
4243

4344
def __del__(self):
44-
os.close(self.gpio_sysfs_value_fd)
45+
if self.gpio_sysfs_value_fd:
46+
os.close(self.gpio_sysfs_value_fd)
4547
self.gpio_sysfs_value_fd = None
4648

4749
def get(self):

0 commit comments

Comments
 (0)