forked from zhanghe06/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_schedule.py
More file actions
58 lines (44 loc) · 1.12 KB
/
test_schedule.py
File metadata and controls
58 lines (44 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
# encoding: utf-8
"""
@author: zhanghe
@software: PyCharm
@file: test_schedule.py
@time: 2016/10/20 下午5:17
"""
import schedule
import time
def job():
print("I'm working...")
print time.strftime('%Y-%m-%d %H:%M:%S')
time.sleep(80)
def run():
# schedule.every(10).minutes.do(job)
# schedule.every().hour.do(job)
# schedule.every().day.at("10:30").do(job)
# schedule.every().monday.do(job)
# schedule.every().wednesday.at("13:15").do(job)
schedule.every().day.at("15:14").do(job)
schedule.every().day.at("15:15").do(job)
while True:
schedule.run_pending()
time.sleep(1)
if __name__ == '__main__':
run()
"""
$ pip install schedule
python 版本的定时调度
注意:
schedule.every().hour.do(job)
调度器开始工作后1个小时开始执行 job
测试执行顺序
设置任务处理时间超过调度间隔:
schedule.every().day.at("15:14").do(job)
schedule.every().day.at("15:15").do(job)
结果:
I'm working...
2017-04-13 15:14:00
I'm working...
2017-04-13 15:15:21
可以看出schedule任务调度是顺序执行,不是并行
"""