【发布时间】:2021-01-23 13:18:31
【问题描述】:
我正在使用调度模块来自动运行一个函数...
我正在考虑动态更改调度时间,但解决方法不成功
代码-
import schedule
import pandas
from time import gmtime, strftime, sleep
import time
import random
time = 0.1
def a():
global time
print(strftime("%Y-%m-%d %H:%M:%S", gmtime()))
index = random.randint(1, 9)
print(index, time)
if(index==2):
time = 1
print(strftime("%Y-%m-%d %H:%M:%S", gmtime()))
schedule.every(time).minutes.do(a) #specify the minutes to automatically run the api
while True:
schedule.run_pending()
在这个程序中,我安排程序每 6 秒运行一次。如果随机整数 - index 值变为 2,则将 time 变量分配为 1(1 分钟)。我查了一下,随机整数index变为2后,time变量变为1。问题-将time变量变为1后,调度仍然每6秒而不是1分钟运行函数a() .
如何动态改变调度时间?
谢谢
【问题讨论】:
标签: python python-3.x scheduled-tasks scheduler