- channel_path = os.path.join(self._sysfs_path, self._channel_path.format(self._channel))
- pin_path = os.path.join(channel_path, self._pin_path.format(self._channel,self._pwmpin))
-
- if self._channel is not None:
- #self.duty_cycle = 0
- self._set_enabled(False) # make to disable before unexport
- try:
- #unexport_path = os.path.join(channel_path, self._unexport_path)
- with open(os.path.join(channel_path, self._unexport_path), "w") as f_unexport:
- f_unexport.write("%d\n" % self._pwmpin)
- except IOError as e:
- raise PWMError(e.errno, "Unexporting PWM pin: " + e.strerror)
- except Exception as e:
- # due to a race condition for which I have not yet been
- # able to find the root cause, deinit() often fails
- # but it does not effect future usage of the pwm pin
- print("warning: failed to deinitialize pwm pin {0}:{1} due to: {2}\n".format(self._channel, self._pwmpin, type(e).__name__))
- finally:
- self._channel = None
- self._pwmpin = None
+ # pylint: disable=broad-except
+ try:
+ channel_path = os.path.join(
+ self._sysfs_path, self._channel_path.format(self._channel)
+ )
+ pin_path = os.path.join(
+ channel_path, self._pin_path.format(self._channel, self._pwmpin)
+ )
+
+ if self._channel is not None:
+ # self.duty_cycle = 0
+ self._set_enabled(False) # make to disable before unexport
+ try:
+ # unexport_path = os.path.join(channel_path, self._unexport_path)
+ with open(
+ os.path.join(channel_path, self._unexport_path), "w"
+ ) as f_unexport:
+ f_unexport.write("%d\n" % self._pwmpin)
+ except IOError as e:
+ raise PWMError(e.errno, "Unexporting PWM pin: " + e.strerror)
+ except Exception as e:
+ # due to a race condition for which I have not yet been
+ # able to find the root cause, deinit() often fails
+ # but it does not effect future usage of the pwm pin
+ print(
+ "warning: failed to deinitialize pwm pin {0}:{1} due to: {2}\n".format(
+ self._channel, self._pwmpin, type(e).__name__
+ )
+ )
+ finally:
+ self._channel = None
+ self._pwmpin = None
+ # pylint: enable=broad-except