任何人都可以帮忙吗,我正在尝试从下面代码中定义的类 PROCESS 中每 x 分钟采样一次数据(只要由此处未显示的其他函数调用时运行)来安排这个,我每 X 分钟运行一个调度程序函数,由 MAIN 函数启动并由函数 minmax_job 执行。
但是我的函数 minmax_job 似乎不知道我尝试过的关于放置全局变量等的初始值,但它仍然不知道 i = 0(最初)
i = 0
atc,otc,tssc = 0,0,0
atf,otf,tssf = False,False,False
class Process(threading.Thread):
def __init__(self, buffer3, broadcast_server):
threading.Thread.__init__(self)
self.setDaemon(True)
self.buffer3 = buffer3
self.factory = broadcast_server
def run(self):
today = datetime.now()
global time_of_last_run
global atv1,atv2,atv3,otv1,otv2,otv3,tssv1,tssv2,tssv3
global atf,otf,tssf
global atc,otc,tssc
if self.buffer3.startswith('kitchen aquarium: temp:'):
self.temp = self.buffer3.replace('kitchen aquarium: temp:','')
self.factory.broadcast("Aquarium temperature %s" % self.temp)
if atc == 1 and atf:
atv1 = float(self.temp)
atf = False
elif atc == 2 and atf:
atv2 = float(self.temp)
atf = False
elif atc == 3 and atf:
atv3 = float(self.temp)
atf = False
def minmax_job():
global atv1,atv2,atv3,otv1,otv2,otv3,tssv1,tssv2,tssv3
global atf,otf,tssf
global atc,otc,tssc,i
if i == 3:
i = 0
atc = 0
if i < 4:
atc = atc + 1
atf = True
i = i + 1
if __name__ == '__main__':
minmax_scheduler = Scheduler()
minmax_scheduler.add_interval_job(minmax_job, seconds=10)
minmax_scheduler.start()