Commits

Jakub Wilk  committed dfb52e2

examples/sensors-alert: reset the led on exit.

  • Participants
  • Parent commits 5b6f1c1

Comments (0)

Files changed (1)

File examples/sensors-alert

 
 temperature_re = re.compile('^ +temp[0-9]+_input: ([0-9.]+)$')
 
-while True:
-    alert = False
-    sensors = subprocess.Popen(['sensors', '-u'], stdout=subprocess.PIPE)
-    for line in sensors.stdout:
-        line = line.rstrip()
-        match = temperature_re.match(line)
-        if match is not None:
-            temperature = match.group(1)
-            temperature = float(temperature)
-            if TEMPERATURE_LIMIT < temperature < TEMPERATURE_BOGUS_LIMIT:
-                alert = True
-    sensors.wait()
-    if alert:
-        i = 0
-        while i * BLINK_SLEEP < SLEEP:
-            if i & 1 == 0:
-                led.set()
-            else:
-                led.reset()
-            time.sleep(BLINK_SLEEP)
-            i += 1
-        led.reset()
-    else:
-        time.sleep(SLEEP)
+try:
+    while True:
+        alert = False
+        sensors = subprocess.Popen(['sensors', '-u'], stdout=subprocess.PIPE)
+        for line in sensors.stdout:
+            line = line.rstrip()
+            match = temperature_re.match(line)
+            if match is not None:
+                temperature = match.group(1)
+                temperature = float(temperature)
+                if TEMPERATURE_LIMIT < temperature < TEMPERATURE_BOGUS_LIMIT:
+                    alert = True
+        sensors.wait()
+        if alert:
+            i = 0
+            while i * BLINK_SLEEP < SLEEP:
+                if i & 1 == 0:
+                    led.set()
+                else:
+                    led.reset()
+                time.sleep(BLINK_SLEEP)
+                i += 1
+            led.reset()
+        else:
+            time.sleep(SLEEP)
+finally:
+    led.reset()
 
 # vim:ts=4 sw=4 et