1

Has anyone else noticed that py-spidev seems to leave a file descriptor open? When I run lsof -p 5833 I see that my program has 5 file descriptors open, which seems fine. When I run sudo lsof -p 5833 I see that py-spidev seems to have left a file descriptor hanging around for every time it's read from the spi bus:

python  6023 root    5u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root    6u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root    7u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root    8u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root    9u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root   10u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root   11u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root   12u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root   13u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root   14u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root   15u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root   16u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root   17u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root   18u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root   19u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root   20u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root   21u   CHR  153,0      0t0    582 /dev/spidev0.0
python  6023 root   22u   CHR  153,0      0t0    582 /dev/spidev0.0

And this goes on and on and on. I need to leave this Pi where it won't get much intervention for a long time. Intuitively it seems like this going to cause some kind of system error where there are simply too many file descriptors hanging around but I'm not sure of the mechanics behind that.

Does anyone have more info on this and know whether it's true of all spi libraries or something particular to the py-spidev library?

1

Actually I've tracked this down to not properly closing the SpiDev:

spi = spidev.SpiDev() # create spi object
spi.open(0, 1)
# do stuff
spi.close()

Rookie mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.