From d9ebec8b314173e0cc5c766567882163adce599d Mon Sep 17 00:00:00 2001 From: Steven Baltakatei Sandoval Date: Sat, 31 Oct 2020 03:53:47 +0000 Subject: [PATCH 1/1] fix(exec/temp):Handle exception from poll script's read function Script was exiting early. Adding exception handling in case `read_temp()` fails. --- exec/temperature/DS18B20..temp_poll.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/exec/temperature/DS18B20..temp_poll.py b/exec/temperature/DS18B20..temp_poll.py index ce2c710..3230bf8 100755 --- a/exec/temperature/DS18B20..temp_poll.py +++ b/exec/temperature/DS18B20..temp_poll.py @@ -43,6 +43,10 @@ myHostname = socket.gethostname() while True: nowTimeIso8601 = strftime("%Y%m%dT%H%M%S%z") nowTimeUE = strftime("%s") - nowTemp = read_temp() - print(str(nowTimeIso8601) + ',' + str(nowTimeUE) + ',' + str(myHostname) + ',' + str(nowTemp), flush=True) # flush to stdout continuously (e.g. without buffer) https://stackoverflow.com/a/14729823 - time.sleep(10) + try: + nowTemp = read_temp() + print(str(nowTimeIso8601) + ',' + str(nowTimeUE) + ',' + str(myHostname) + ',' + str(nowTemp), flush=True) # flush to stdout continuously (e.g. without buffer) https://stackoverflow.com/a/14729823 + except Exception as e: + print(str(nowTimeIso8601) + ',' + str(nowTimeUE) + ',' + str(myHostname) + ',' + 'ERROR:' + str(e), flush=True) + finally: + time.sleep(10) -- 2.30.2