classification
Title: Multiprocessing Pool example and comments incomplete/wrong?
Type: Stage:
Components: Documentation Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, mutax
Priority: normal Keywords:

Created on 2021-07-12 22:18 by mutax, last changed 2021-07-12 22:18 by mutax.

Messages (1)
msg397360 - (view) Author: Florian Streibelt (mutax) Date: 2021-07-12 22:18
The docs at the url

https://docs.python.org/3/library/multiprocessing.html#module-multiprocessing.pool

state in a red warning box:

"Warning

multiprocessing.pool objects have internal resources that need to be properly managed (like any other resource) by using the pool as a context manager or by calling close() and terminate() manually. Failure to do this can lead to the process hanging on finalization."


however, when using the context manager, as it is also shown in the examples, the context manager will call terminate() instead of close() and join() on the pool, possible leading to deadlocks if I understand the documentation correct.

It seems the only safe way of using a Pool as Context Manager is to manually call pool.close() and pool.join() prior to leaving it, which, to be honest, does not make sense to me.


see pool.py:

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.terminate()
History
Date User Action Args
2021-07-12 22:18:36mutaxcreate