- import threading,time
- class Demo(threading.Thread):
- def __init__(self,color):
- threading.Thread.__init__(self)
- self.color=color
- def run(self):
- for i in xrange(3):
- print "hello,world", i, self.isAlive(),self.color
- time.sleep(1)
- list=[]
- for i in xrange(2):
- test=Demo('green')
- #test.setDaemon(True)
- test.start()
- list.append(test)
- for test in list:
- test.join(15)
- print test.isAlive( ) #### it must be 'False' "
- print "main threading exit
test.setDaemon(True),主线程退出,子线程也随着退出。
阅读(1116) | 评论(0) | 转发(0) |