May-28-2019, 07:48 PM
I'm composing a simple temperature alarm notification system, and I'm stuck. I have everything working great with the exception of some scheduled functions ("reminder of active alarm" and "a weekly communication test". Currently I'm trying the "schedule module" but I'm having the same problems I did when I tried using "Timer=" and "threading" to accomplish this task. It appears that these function take a snapshot of the task and recycles it. I can't seem to get it to pull "current variables" like datetime and current temp before it executes the task. I'm pretty sure my problem is somewhere in *args & *kwargs but I can't figure it out. I've read the py.docs and googled the hell out of this, but I keep getting lost and I can't find an answer. None of the examples seem to illustrate this and I got no one to ask. I'm self-taught and I have to say I'm pretty impressed with how far I got. But, I'm stuuuck!! I've been banging my head on this little quirky problem for 4 days now. How does one pull current variables into a scheduled, timer or threaded function. Attached is a snip of my code where I think the problem is. If you run it, it illustrates the problem I'm referring to. datetime and currenttemp are getting recycled and are not getting updated prior to execution of the task/ I know I'm doing something fundamentally wrong, because I was getting similar results when I tried to use a timer and threading to accomplish this task.
import schedule #import threading import time from datetime import datetime currenttime = datetime.now() #hr = int(currenttime.strftime("%-H")) dt = currenttime.strftime("%c") tempss = 1 #sensor status tempsh = 1 #sensor history currenttemp = 43 #random set value, actual value called from device file. def job(): print (message) #actual job script contains smtp protocals with execute send while True: if tempss ==1 and tempsh == 1: message= """ Alarm is still activated Current temperature is {}F {}""".format (currenttemp, dt) schedule.every(1).minutes.do(job), dt schedule.run_pending() else: schedule.cancel_job()