From: Steven Baltakatei Sandoval Date: Sat, 31 Oct 2020 03:53:47 +0000 (+0000) Subject: fix(exec/temp):Handle exception from poll script's read function X-Git-Url: https://zdv2.bktei.com/gitweb/EVA-2020-02.git/commitdiff_plain/d9ebec8b314173e0cc5c766567882163adce599d fix(exec/temp):Handle exception from poll script's read function Script was exiting early. Adding exception handling in case `read_temp()` fails. --- 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)