This shows you the differences between two versions of the page.
— |
pythonsched [2014/10/25 21:52] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ==== Python scheduler example ==== | ||
+ | <code lang="python"> | ||
+ | import sched | ||
+ | import time | ||
+ | import datetime | ||
+ | import os | ||
+ | |||
+ | __fifteenMins = 15 * 60 | ||
+ | __cmd = "sqlplus scott/tiger@oradb @c:\madan\sql\update_rows.sql" | ||
+ | s=sched.scheduler(time.time, time.sleep) | ||
+ | def print_time(): | ||
+ | try: | ||
+ | print "From print_time", datetime.datetime.now() | ||
+ | except: | ||
+ | print "Abort print_time()" | ||
+ | pass | ||
+ | |||
+ | def print_some_times(): | ||
+ | try: | ||
+ | print datetime.datetime.now() | ||
+ | s.enter(__fifteenMins, 1, print_time, ()) | ||
+ | s.run() | ||
+ | os.system(__cmd) | ||
+ | print_some_times() | ||
+ | except: | ||
+ | print "Abort" | ||
+ | pass | ||
+ | |||
+ | print_some_times() | ||
+ | </code> | ||
+ | |||
+ | ---- | ||
+ | * [[pythoninfo|Back to Python]] | ||