Skip to content

Instantly share code, notes, and snippets.

@mvallebr
Created November 30, 2015 14:10
Show Gist options
  • Select an option

  • Save mvallebr/b1b0b23afa1fe0d78d7e to your computer and use it in GitHub Desktop.

Select an option

Save mvallebr/b1b0b23afa1fe0d78d7e to your computer and use it in GitHub Desktop.
import sys
import threading
import logging
class EventScheduler(threading.Thread):
def __init__(self, event_callback, interval):
logging.info("creating scheduler")
super(EventScheduler, self).__init__()
self.setDaemon(True)
self.event_callback = event_callback
self.interval = int(interval)
def run(self):
logging.info("Scheduler Created")
while True:
try:
self.event_callback()
except Exception as e:
logging.error(str(e))
time.sleep(self.interval)
# Usage
def my_callback():
print "callback called"
scheduler = EventScheduler(my_callback, 5)
scheduler.start()
while True:
sys.sleep(1) # daemon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment