Skip to content

Instantly share code, notes, and snippets.

@wasabi0522
Created September 15, 2011 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wasabi0522/1219359 to your computer and use it in GitHub Desktop.
Save wasabi0522/1219359 to your computer and use it in GitHub Desktop.
isAlive test
import threading
import time
class subThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.setDaemon(True)
print "================= sub Listened"
def run(self):
print "=================== sub started"
i = 1
while i < 1000:
print "=== sub loop", i
i += 1
print "=== sub finish"
class mainThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.setDaemon(True)
print "================= main Listened"
self.server = subThread()
def run(self):
print "=================== main started"
self.server.start()
while self.server.isAlive():
time.sleep(1)
print "=== main finish"
if __name__=='__main__':
main = mainThread()
main.start()
while main.isAlive():
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment