我在python中导入计划包,我需要运行我的任务,例如n:00从1:00开始,每10分钟1:30结束(每天3次),需要重复此模式,直到n天完成。 非常感谢!
答案 0 :(得分:1)
如何安排工作:https://schedule.readthedocs.io/en/stable/
如何清除预定作业:https://schedule.readthedocs.io/en/stable/faq.html#clear-job-by-tag
import schedule
n_days = 5 # Run for 5 days
tasks_done = 0 # Track number of times this is run
tasks_per_day = 3 # No of times this task runs
def do_task():
global tasks_done, tasks_per_day, n_days
tasks_done += 1
print("I'm working...")
if tasks_done >= (tasks_per_day * n_days):
# N Days are over
schedule.clear('daily-tasks')
times = ["01:00", "01:10", "01:20"]
for t in times:
schedule.every().day.at(t).do(do_task).tag('daily-tasks', t)