If I want to give more work to my Process Pool, can I call Pool.join() before Pool.close()?

南楼画角 提交于 2020-02-24 06:45:05

问题


The documentation for multiprocessing states the following about Pool.join():

Wait for the worker processes to exit. One must call close() or terminate() before using join().

I know that Pool.close() prevents any other task from being submitted to the pool; and that Pool.join() waits for the pool to finish before proceeding with the parent process.

So, why can I not call Pool.join() before Pool.close() in the case when I want to reuse my pool for performing multiple tasks and then finally close() it much later? For example:

pool = Pool()
pool.map(do1)
pool.join() # need to wait here for synchronization
.
.
.
pool.map(do2)
pool.join() # need to wait here again for synchronization
.
.
.
pool.map(do3)
pool.join() # need to wait here again for synchronization
pool.close()

# program ends

Why must one "call close() or terminate() before using join()"?

来源:https://stackoverflow.com/questions/59618300/if-i-want-to-give-more-work-to-my-process-pool-can-i-call-pool-join-before-po

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!