该
Pool文档没有提到将多个参数传递给目标函数的方法-我尝试了传递一个序列,但没有展开(每个参数序列的一项)。
但是,您可以编写目标函数以使第一个(也是唯一一个)参数成为元组,其中每个元素都是您期望的参数之一:
from itertools import repeatdef insert_and_process((file_to_process,db)): db = DAL("path_to_mysql" + db) #Table Definations db.table.insert(**parse_file(file_to_process)) return Trueif __name__=="__main__": file_list=os.listdir(".") P = Pool(processes=4) P.map(insert_and_process,zip(file_list,repeat(db)))(请注意-
python定义中的多余括号将
insert_and_processpython视为应为2个项目的序列的单个参数。序列的第一个元素归属于第一个变量,另一个归因于第二个变量)



