Created
February 6, 2013 23:59
-
-
Save contumaxcs/4727082 to your computer and use it in GitHub Desktop.
Python: Timer
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
| #!/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