Created
June 2, 2017 06:32
-
-
Save winstonma/1cef3927ce716170966b05832a6bfae5 to your computer and use it in GitHub Desktop.
APScheduler Blocking Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Demonstrates how to use the blocking scheduler to schedule a job that executes on 3 second | |
intervals. | |
""" | |
from datetime import datetime | |
import os | |
import threading | |
from apscheduler.schedulers.blocking import BlockingScheduler | |
def tick(): | |
print('Tick! The time is: %s' % datetime.now()) | |
print('Thread Count: %d' % threading.active_count()) | |
if __name__ == '__main__': | |
scheduler = BlockingScheduler() | |
scheduler.add_job(tick, 'interval', seconds=3) | |
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C')) | |
try: | |
scheduler.start() | |
except (KeyboardInterrupt, SystemExit): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment