http://python.jobbole.com/86822/
http://www.cnblogs.com/hanybblog/p/6225797.html
兩個線程,第一個立即執(zhí)行完成,輸出了'all end',第二個sleep之后,最后也輸出'all end'
'''
import os
import datetime
import threading
import pymongo
from time import sleep
#----------------------------------------------------------------------
def t1(name1):
""""""
for i in xrange(5):
print i
print name1 + ' ' + str(datetime.datetime.now())
#----------------------------------------------------------------------
def t2(name2):
""""""
for i in xrange(6,10):
print i
sleep(3)
print name2 + ' ' + str(datetime.datetime.now())
threads = []
th1 = threading.Thread(target=t1, args=('This is t1',))
threads.append(th1)
th2 = threading.Thread(target=t2, args=('This is t2',))
threads.append(th2)
for i in threads:
i.setDaemon(True)
i.start()
for i in threads:
i.join()
print 'all end'
image.png