import time
from concurrent.futures import ThreadPoolExecutor
成都創(chuàng)新互聯公司專注于企業(yè)成都全網營銷、網站重做改版、集美網站定制設計、自適應品牌網站建設、H5頁面制作、商城網站制作、集團公司官網建設、成都外貿網站建設、高端網站制作、響應式網頁設計等建站業(yè)務,價格優(yōu)惠性價比高,為集美等各大城市提供網站開發(fā)制作服務。
def test(name):
print "write to db " + name
name_list = ['Lucy', 'Lily', 'Tom', 'Lucy2', 'Lily2', 'Tom2', 'Lucy3', 'Lily3', 'Tom3']
#start = time.time()
#for i in range(9):
#test(name_list[i])
#end = time.time()
#print end - start # 7.00950622559e-05
pool = ThreadPoolExecutor(max_workers=3)
start = time.time()
for i in range(9):
test(name_list[i])
pool.submit(test, name_list[i])
pool.shutdown(wait=True) # pool.shutdown(wait=True)是進程池內部的進程都執(zhí)行完畢,才會關閉,然后執(zhí)行后續(xù)代碼
end = time.time()
print end - start # 0.0054759979248