forked from ls1248659692/python_guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedule_safe.py
More file actions
41 lines (28 loc) · 764 Bytes
/
schedule_safe.py
File metadata and controls
41 lines (28 loc) · 764 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
#!/usr/bin/python
# coding=utf8
import Queue
import time
import threading
import schedule
__author__ = 'Jam'
__date__ = '2019/3/29 14:23'
jobqueue = Queue.Queue()
def job():
print "I'm working"
def worker_main():
while True:
job_func = jobqueue.get()
job_func()
def run():
schedule.every(10).seconds.do(jobqueue.put, job)
schedule.every(10).seconds.do(jobqueue.put, job)
schedule.every(10).seconds.do(jobqueue.put, job)
schedule.every(10).seconds.do(jobqueue.put, job)
schedule.every(10).seconds.do(jobqueue.put, job)
worker_thread = threading.Thread(target=worker_main)
worker_thread.start()
while True:
schedule.run_pending()
time.sleep(1)
if __name__ == '__main__':
run()