问题
The documentation for multiprocessing states the following about Pool.join():
Wait for the worker processes to exit. One must call
close()orterminate()before usingjoin().
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