Python多进程处理文件
Python多进程multiprocessing模块
apply_async (异步非阻塞)的方式执行函数
p.join()的意思是等待所有结果执行完毕,等待所有子进程执行完毕
import os
import csv
from multiprocessing import Pool
path = "./xxx/"
files = os.listdir(path)
def function(i):
list=[]
with open(path+str(i),encoding="utf-8") as f :
reader=csv.reader(f)
for row in reader:
list.append(row)
print(len(list))
if __name__=="__main__":
p=Pool(16)
for i in files:
p.apply_async(function,args=(i,))
p.close()
p.join()