Hi, I have this code that includes a sort of watch dog within a try block inside a while loop
I don't understand two things:
1) why sometimes, not always, it is generated the error;
2) why, because of this error, the program get closed and exits instead of going ahead with the while loop
This simple script should run forever (while loop) and the file my_time.txt is a simple file where another python program write last time its code is executed.
This is the code that write the timestamp in my_time.txt every 15 seconds
Thanks a lot to all
I don't understand two things:
1) why sometimes, not always, it is generated the error;
2) why, because of this error, the program get closed and exits instead of going ahead with the while loop
This simple script should run forever (while loop) and the file my_time.txt is a simple file where another python program write last time its code is executed.
This is the code that write the timestamp in my_time.txt every 15 seconds
import time with open(my_time.txt,"w") as Time_check: Time_check.write(str(time.time()))this is the code I need help
import time while True: try: with open(my_time.txt,"r") as Time_check: print(Time_check.read()) Time_value=float(Time_check.read()) #This line generates the error Delta_time = (time.time()-Time_value) if Delta_time > 30: #30 seconds do FOO else: do FOO_ except: print (sys.exc_info()[0]) print (sys.exc_info()[1]) print (sys.exc_info()[2])This is the error that sometimes get generated
Error:<type 'exceptions.ValueError'>
could not convert string to float:
<traceback object at 0x0000000003A70348>
Last time I got this error, the timestamp written inside the my_time.txt was 1593707454.53Thanks a lot to all