這篇文章主要介紹多個數(shù)據(jù)怎么用python3中的多線程處理,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!
第一步:import threading 模塊
import threading
第二步:改下一下代碼:
既可以同時打開并運(yùn)行多個文件
import operator import csv import time import threading from time import ctime def read_file(filpos,i): with open(filpos+str(i)+".csv") as f: reader=csv.reader(f) for i in reader: print(i) threads = [] x=0 for t in range(0,3): t= threading.Thread(target=read_file,args=("D:/zhihu/",x)) threads.append(t) x+=1 #join在里面時候只有第一個子進(jìn)程結(jié)束才能打開第二個進(jìn)程,if__name__ 調(diào)用時不可用 if __name__=="__main__": for thr in threads: thr.start() thr.join() print("all over %s"%ctime())
就是把文件添加到線程池里面,再一起執(zhí)行。
以上是“多個數(shù)據(jù)怎么用python3中的多線程處理”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!