diff options
Diffstat (limited to 'examples/interval.py')
-rw-r--r-- | examples/interval.py | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/examples/interval.py b/examples/interval.py index e449c15..e16596c 100644 --- a/examples/interval.py +++ b/examples/interval.py @@ -1,27 +1,22 @@ """ Basic example showing how to start the scheduler and schedule a job that -executes on 3 second intervals. It uses sys.stdout.write instead of print to -allow it to work unmodified on both Python 2.x and 3.x. +executes on 3 second intervals. """ from datetime import datetime -import sys -import time from apscheduler.scheduler import Scheduler def tick(): - sys.stdout.write('Tick! The time is: %s\n' % datetime.now()) + print('Tick! The time is: %s' % datetime.now()) if __name__ == '__main__': - scheduler = Scheduler() + scheduler = Scheduler(standalone=True) scheduler.add_interval_job(tick, seconds=3) - sys.stdout.write('Press Ctrl+C to exit\n') - scheduler.start() - - # This is here to prevent the main thread from exiting so that the - # scheduler has time to work -- this should not be necessary in real world - # applications - time.sleep(9999) + print('Press Ctrl+C to exit') + try: + scheduler.start() + except (KeyboardInterrupt, SystemExit): + pass |