python3-gpiod
python3-gpiod copied to clipboard
Leaking open files when running gpiod.find_line()
This is a small step-by-step to reproduce the error:
- Have a named pin on any chip above gpiochip0.
- Run this code, substitute the GPIO_NAME:
import gpiod
for i in range(1025):
a = gpiod.find_line("GPIO_NAME")
This results in an error about too many open files. Error:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/lib/python3.10/site-packages/gpiod/__init__.py", line 48, in find_line
File "/usr/lib/python3.10/site-packages/gpiod/libgpiodcxx/__init__.py", line 1285, in __iter__
File "/usr/lib/python3.10/site-packages/gpiod/libgpiod/__init__.py", line 1195, in __iter__
File "/usr/lib/python3.10/site-packages/gpiod/libgpiod/__init__.py", line 118, in gpiod_chip_open
File "/usr/lib/python3.10/site-packages/gpiod/libgpiod/__init__.py", line 89, in _is_gpiochip_cdev
OSError: [Errno 24] Too many open files: '/sys/bus/gpio/devices/gpiochip0/dev'
Potential reason is that find_line doesn't properly close file descriptors when going through the chips. Can not reproduce on gpiochip0 or when trying to find a pin that doesn't exists.