您好,登錄后才能下訂單哦!
import time
from concurrent.futures import ThreadPoolExecutor
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)是進程池內部的進程都執行完畢,才會關閉,然后執行后續代碼
end = time.time()
print end - start # 0.0054759979248
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。