Skip to content

Instantly share code, notes, and snippets.

@lejarx
Created January 12, 2016 15:18
Show Gist options
  • Save lejarx/fc8e1978489597b93306 to your computer and use it in GitHub Desktop.
Save lejarx/fc8e1978489597b93306 to your computer and use it in GitHub Desktop.
"""
Demonstrates how to use the blocking scheduler to schedule a job that executes on 3 second
intervals.
"""
from datetime import datetime
import os
from apscheduler.schedulers.blocking import BlockingScheduler
def tick():
print('Tick! The time is: %s' % datetime.now())
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