所以我有一个函数,它只通过两个参数对几个.txt文件执行一些操作。它目前正在按预期工作,但我在近一个小时内就完成了10%的东西 - 所以需要一些时间,因为.txt文件相当大。具有两个参数的函数的多处理(池)
现在,我已经阅读了关于程序包多重处理的内容,尤其是其中的Pool段。但是,我不太清楚我如何正确使用它。
我用它来运行我的函数的代码如下:
for k, structure in enumerate(structures):
structure_maker(structure_path, structure)
的structure_path
始终是相同的,而structures
是不同值的列表,如:
structures = [1, 3, 6, 7, 8, 10, 13, 25, 27]
所以我将如何去使用这个池进程? 至于我可以阅读我必须做一些事情,如:
from multiprocessing import Pool
mypool = Pool(6) # Choosing how many cores I want to use
mypool.map(structure_maker, list)
而且list
是我迷路。那应该是什么? structures
列表,如果是的话,我在哪里可以放入我的structure_path
?