- 論壇徽章:
- 0
|
原帖由 bohemia 于 2009-1-6 09:13 發(fā)表 ![]()
默認Main Thread退出,所有的Sub Thread都會退出的; (大部分操作系統(tǒng)是這樣的, SGI IRIX例外).
在python里,如果一個進程的主線程運行完畢而子線程還在執(zhí)行的話,那么進程就不會退出,直到所有子線程結(jié)束為止。
你可以用下面的試一下,看看有setDaemon()和沒有setDaemon()的區(qū)別
import threading
import time
class mythread(threading.Thread):
def __init__(self, threadname):
threading.Thread.__init__(self, name = threadname)
def run(self):
for i in range(10):
print self.getName, i
time.sleep(1)
t=mythread("ttt")
t.setDaemon(True)
t.start()
print "main" |
|