Skip to content

Instantly share code, notes, and snippets.

@draganHR
Created March 24, 2015 10:39
Show Gist options
  • Save draganHR/90415b8c51a2b06ee26a to your computer and use it in GitHub Desktop.
Save draganHR/90415b8c51a2b06ee26a to your computer and use it in GitHub Desktop.
periodic python scheduler
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()
@draganHR
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment