Skip to content

Instantly share code, notes, and snippets.

@contumaxcs
Created February 6, 2013 23:59
Show Gist options
  • Select an option

  • Save contumaxcs/4727082 to your computer and use it in GitHub Desktop.

Select an option

Save contumaxcs/4727082 to your computer and use it in GitHub Desktop.
Python: Timer
#!/usr/bin/python
import threading
import time
class TimerClass(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()
def run(self):
while not self.event.is_set():
print "do something"
self.event.wait(1)
def stop(self):
self.event.set()
tmr = TimerClass()
tmr.start()
time.sleep(10)
tmr.stop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment