python用schedule模块实现定时任务

1 import schedule
2 import time
3
4 def test():
5 print("I'm working...")
6 def test2():
7 print("I'm working... in job2")
8
9 # 每10分钟执行一次job函数
10 schedule.every(10).minutes.do(test)
11 # 每10秒执行一次job函数
12 schedule.every(10).seconds.do(test)
13 # 当every()没参数时默认是1小时/分钟/秒执行一次job函数
14 schedule.every().hour.do(test)
15 schedule.every().day.at("10:30").do(test)
16 schedule.every().monday.do(test)
17 # 具体某一天某个时刻执行一次job函数
18 schedule.every().wednesday.at("13:15").do(test)
19 # 可以同时定时执行多个任务,但是每个任务是按顺序执行
20 schedule.every(10).seconds.do(job2)
21 # 如果job函数有有参数时,这么写
22 schedule.every(10).seconds.do(job,"参数")
23 while True:
24 # 启动服务
25 schedule.run_pending()
26 time.sleep(1)

上一篇:LVS 实现负载均衡原理及安装配置详解


下一篇:arcgispro字段计算器