summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authoragronholm <devnull@localhost>2010-12-12 04:49:53 +0200
committeragronholm <devnull@localhost>2010-12-12 04:49:53 +0200
commita714e54f0949b977a9ae663d3cc9b0e64c8a1e8e (patch)
tree9e5af8145f644f72a3f929111bd7daa77bb5e8d7 /examples
parent5e01b0dce13e43feb1924df786cee0cbdf41e740 (diff)
downloadapscheduler-a714e54f0949b977a9ae663d3cc9b0e64c8a1e8e.tar.gz
Added simple example demonstrating the use of interval scheduling
Diffstat (limited to 'examples')
-rw-r--r--examples/interval.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/examples/interval.py b/examples/interval.py
new file mode 100644
index 0000000..e449c15
--- /dev/null
+++ b/examples/interval.py
@@ -0,0 +1,27 @@
+"""
+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.
+"""
+
+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())
+
+
+if __name__ == '__main__':
+ scheduler = Scheduler()
+ 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)