我想为列表的每个项目创建一个进程实例。该过程应该一次只创建一个,新过程应该只在它完成之前创建。我该怎么做?
下面的代码不起作用,它只打印IP列表。
def performwork(IP):
.................
.................
for IP in listOfIPs:
print IP
multiprocessing.Process(target = performwork, args=(IP))
答案 0 :(得分:1)
from contextlib import closing
from multiprocessing import Pool
with closing(Pool(processes=1)) as pool:
pool.map(performwork, listOfIPs)