forked from ls1248659692/python_guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedule_tutorial.py
More file actions
44 lines (29 loc) · 746 Bytes
/
schedule_tutorial.py
File metadata and controls
44 lines (29 loc) · 746 Bytes
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
#!/usr/bin/python
# coding=utf8
import datetime
import threading
import time
import schedule
__author__ = 'Jam'
__date__ = '2019/3/29 14:01'
def job1():
print "I'm working for job1"
time.sleep(2)
print "job1:", datetime.datetime.now()
def job2():
print "I'm working for job2"
time.sleep(2)
print "job2:", datetime.datetime.now()
def job2_task():
threading.Thread(target=job2).start()
def run_threaded(job_func):
job_thread = threading.Thread(target=job_func)
job_thread.start()
def run():
schedule.every(10).seconds.do(run_threaded,job1)
# schedule.every(10).seconds.do(job2_task)
while True:
schedule.run_pending()
time.sleep(1)
if __name__ == '__main__':
run()