Skip to content

Instantly share code, notes, and snippets.

@ekratskih
Created August 21, 2012 05:02
Show Gist options
  • Save ekratskih/3411808 to your computer and use it in GitHub Desktop.
Save ekratskih/3411808 to your computer and use it in GitHub Desktop.
Tracking thread
#!/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