From c7814c39a76fc4e47dfa0706f6468924570c3230 Mon Sep 17 00:00:00 2001 From: petrucci4prez Date: Sat, 17 Jun 2017 14:44:29 -0400 Subject: [PATCH] no busy wait in blinkenlights --- blinkenLights.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/blinkenLights.py b/blinkenLights.py index bcb2f85..46bdc5b 100644 --- a/blinkenLights.py +++ b/blinkenLights.py @@ -25,14 +25,14 @@ class Blinkenlights(ExceptionThread): def blinkLights(): pwm.start(0) while not self._stopper.isSet(): - t = self._sleeptime if self._blink.is_set(): + t = self._sleeptime for dc in chain(range(100, -1, -5), range(0, 101, 5)): pwm.ChangeDutyCycle(dc) time.sleep(t) else: pwm.ChangeDutyCycle(100) - time.sleep(t) + self._blink.wait() pwm.stop() # required to avoid core dumps when process terminates super().__init__(target=blinkLights, daemon=True) @@ -44,6 +44,7 @@ class Blinkenlights(ExceptionThread): def stop(self): if self.is_alive(): self._stopper.set() + self._blink.set() logger.debug('Stopping LED on pin %s', self._pin) def setCyclePeriod(self, cyclePeriod):