Created
September 15, 2011 14:22
-
-
Save wasabi0522/1219359 to your computer and use it in GitHub Desktop.
isAlive test
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
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