blob: 8b23402c8fd17412bce19f5b1ba0e759b1003135 (
plain)
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
|
"""
Demonstrates how to use the gevent compatible scheduler to schedule a job that executes on 3 second
intervals.
"""
from datetime import datetime
import os
from apscheduler.schedulers.gevent import GeventScheduler
def tick():
print('Tick! The time is: %s' % datetime.now())
if __name__ == '__main__':
scheduler = GeventScheduler()
scheduler.add_job(tick, 'interval', seconds=3)
g = scheduler.start() # g is the greenlet that runs the scheduler loop
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
# Execution will block here until Ctrl+C (Ctrl+Break on Windows) is pressed.
try:
g.join()
except (KeyboardInterrupt, SystemExit):
pass
|