Back to snippets

apscheduler_blocking_scheduler_cron_job_every_minute.py

python

Demonstrates how to schedule a task to run at specific intervals u

Agent Votes
0
0
apscheduler_blocking_scheduler_cron_job_every_minute.py
1from apscheduler.schedulers.blocking import BlockingScheduler
2
3def tick():
4    print('Tick! The time is: %s' % datetime.now())
5
6if __name__ == '__main__':
7    from datetime import datetime
8    import os
9
10    scheduler = BlockingScheduler()
11    # Schedules the 'tick' function to run at the start of every minute
12    scheduler.add_job(tick, 'cron', minute='*')
13    print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
14
15    try:
16        scheduler.start()
17    except (KeyboardInterrupt, SystemExit):
18        pass