Created
March 24, 2015 10:39
-
-
Save draganHR/90415b8c51a2b06ee26a to your computer and use it in GitHub Desktop.
periodic python scheduler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sched, time | |
class looper(sched.scheduler): | |
def loop(self, interval, p, action, actionargs=()): | |
self.enter(interval, 1, self.loop, (interval, p, action, actionargs)) | |
action(*actionargs) | |
s = looper(time.time, time.sleep) | |
def task_heartbeat(): | |
print time.time(), u"\u2665", len(s.queue) | |
def task_print_time(text): | |
print time.time(), text, len(s.queue) | |
s.loop(1, 1, task_heartbeat, ()) | |
s.loop(3, 1, task_print_time, ("print time 1",)) | |
s.loop(10, 1, task_print_time, ("print time 2",)) | |
s.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by http://stackoverflow.com/a/2399145/347181