【发布时间】:2020-10-23 08:53:41
【问题描述】:
如何从今天开始每天随机运行计划作业?我想使用schedule 包。
pip install schedule
import schedule
def job()
print("foo")
return schedule.CancelJob
while True:
time_str = '{:02d}:{:02d}'.format(random.randint(6, 10), random.randint(0, 59))
print("Scheduled for {}".format(time_str))
schedule.every().day.at(time_str).do(job)
schedule.run_pending()
上面的代码只是旋转:
Scheduled for 06:36
Scheduled for 10:00
Scheduled for 06:18
【问题讨论】:
-
如果您使用的是 unix 操作系统并通过那里设置随机时间,您也许可以使用 crontab?
-
需要在 Windows 和 Linux 上运行,我希望所有逻辑都在一个包中。