classification
Title: Multiprocessing.Pool maxtasksperchild=1 doesn't work
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Gabriel Tardif, docs@python
Priority: normal Keywords:

Created on 2020-01-26 22:30 by Gabriel Tardif, last changed 2020-01-30 09:18 by Gabriel Tardif. This issue is now closed.

Files
File name Uploaded Description Edit
reader.py Gabriel Tardif, 2020-01-26 22:30 Short python exemple where the problem occur
Messages (2)
msg360736 - (view) Author: Gabriel Tardif (Gabriel Tardif) * Date: 2020-01-26 22:30
Hello

This bug is about the maxtasksperchild parameter in the Pool object constructor of the multiprocessing module.

When you set processes = 1 in the Pool constructor
maxtasksperchild value is double by two for unknow raison whatever the maxtaskperchild value.

As mentionned in the documentation, once the process has reach the maxtasksperchil value it should rebuild itself in the memory from the parent process.

In the short python exemple provided below, you can see the value of showedFiles of each process incresing over 1 which is not normal if Pool constructor is set to processes = 1, maxtasksperchil = 1.

The only running process should destroy / reset itself and so set its value 'showedFiles' to 0 first and 1 for each os.listdir() entry.
msg361026 - (view) Author: Gabriel Tardif (Gabriel Tardif) * Date: 2020-01-30 09:18
Be aware that maxtasksperchild work together with the chunksize parameter of the map fonction when you use it and the default chunksize value is not 1, it's calculated according to your inputs, process and other parameters.
History
Date User Action Args
2020-01-30 09:18:37Gabriel Tardifsetstatus: open -> closed
stage: resolved
2020-01-30 09:18:28Gabriel Tardifsetresolution: not a bug
messages: + msg361026
2020-01-26 22:30:15Gabriel Tardifcreate