检查processpool是否完成了对python3的处理

时间:2018-01-04 11:46:35

标签: python-3.x parallel-processing

如何检查进程池中是否已完成进程安排?我只需要在完成进程池后执行其余的代码就有办法吗?

 executornan = concurrent.futures.ProcessPoolExecutor(20)      

    for l, ch in enumerate(chunks):
                print("CHUNK NUMBEr", l)
                print("CHUNKS", ch)
                futuresnan = [executornan.submit(locals()[configid + 5].ftptester, ch)]

1 个答案:

答案 0 :(得分:0)

你应该使用shutdown:

for l, ch in enumerate(chunks):
            print("CHUNK NUMBEr", l)
            print("CHUNKS", ch)
            futuresnan = [executornan.submit(locals()[configid + 5].ftptester, ch)]
executornan.shutdown(wait=True)

这将等到所有任务完成后再关闭池。

注意:如果您不需要在功能之外声明游泳池,也可以使用with

with concurrent.futures.ProcessPoolExecutor(20) as executornan:
    for l, ch in enumerate(chunks):
         print("CHUNK NUMBEr", l)
         print("CHUNKS", ch)
         futuresnan = [executornan.submit(locals()[configid + 5].ftptester, ch)]

当您点击这部分代码,提交任务,然后等待所有这些任务完成然后退出with结构时,这将创建一个新池。

相关问题