vsergeev / python-periphery

A pure Python 2/3 library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
MIT License
531 stars 142 forks source link

About PWM class #22

Closed nopnop2002 closed 4 years ago

nopnop2002 commented 5 years ago

GPIO class maintains open file descriptor as self._fd. also I2C class maintains open file descriptor as self._fd. but PWM class don't maintains open file descriptor of /sys/class/pwm/pwmchipX/pwmX, and It open file Each method(period, frequency,polarity). So It open /sys/class/pwm/pwmchipX/pwmX many times. And never close file system. Is this right?

vsergeev commented 4 years ago

Each of the files are opened in a context manager, so they're closed automatically after the read or write. You're right that they will be reopened and closed as many times as the properties are modified, but the contributor likely designed the module assuming infrequent modifications.

I'm open to modifications if there is a compelling reason to keep them open and rewind after reading/writing.