我在一个调用这段代码的循环中启动了几个python进程:
startTimeMillis = int(round(time.time() * 1000))
for i in range(10):
p = multiprocessing.Process(target=performCurl, args =("http://www.google.com/d", i, ))
p.start()
endTimeMillis = int(round(time.time() * 1000))
totalTimeSeconds = (endTimeMillis - startTimeMillis)
print "The whole process took ", str(totalTimeSeconds)
我想检查所有进程完成所需的时间,那么如何让代码的最后一部分等待所有进程呢?
答案 0 :(得分:7)
使用p.join()
等待进程终止
all_processes = [multiprocessing.Process(...) for ... in ...]
for p in all_processes:
p.start()
for p in all_processes:
p.join()