The code below is in a thread. The code is copied from an answer to a question asked here a couple of years ago (unfortenately I can't find the question at the moment). Though it looks sound to me, I get an error: "ValueError: sleep length must be non-negative". This happens only after about an hour or so. Could it be that it has to do something with the PC going to sleep (I think unlikely, but it's a laptop running Windows 10 ;-)). This is the code:
def upd_variables():
next_call = time.time()
while True:
measured_temp = 19.5 # te wijzigen in uitlezing van de sensor
acttemp.configure(text = str(measured_temp))
humi = '49.5' # te wijzigen in uitlezing van de sensor
humidity.configure(text = humi)
actdaytime = datetime.datetime.now()
today = actdaytime.strftime("%A %d %B %Y %H:%M:%S")
datumtijd.configure(text=today)
if (measured_temp < desired_temp):
#CV aan
status.configure(text="CV aan")
else:
#CV uit
status.configure(text="CV uit")
next_call = next_call+1;
time.sleep(next_call - time.time())
I hope this is readable, I'm not sure the code block will look like I want it to... BTW: it is part of a thermostat program I'm working on, intended to run on a Raspberry Pi.