Created
August 21, 2012 05:02
-
-
Save ekratskih/3411808 to your computer and use it in GitHub Desktop.
Tracking thread
This file contains 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/env python | |
import threading | |
import time | |
class TrackingThread(threading.Thread): | |
def __init__(self, *args, **kwargs): | |
super(TrackingThread, self).__init__(*args, **kwargs) | |
self._stop = threading.Event() | |
def run(self): | |
while True: | |
if self.stopped(): | |
print "Stop thread" | |
break | |
print "Tracking thread" | |
time.sleep(1) | |
def stop(self): | |
self._stop.set() | |
def stopped(self): | |
return self._stop.isSet() | |
def main(): | |
while True: | |
print "Main thread" | |
time.sleep(1) | |
if __name__ == '__main__': | |
track = TrackingThread() | |
track.start() | |
try: | |
main() | |
except: | |
track.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment