This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: multiprocessing.Pool with maxtasksperchild starts too many processes
Type: resource usage Stage:
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Zahari.Dim
Priority: normal Keywords:

Created on 2015-06-27 09:22 by Zahari.Dim, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (1)
msg245878 - (view) Author: Zahari Dim (Zahari.Dim) Date: 2015-06-27 09:22
The following example should start two processes, but instead it starts three, even though only two do_work(). A third process is incorrectly started after the first one finishes.

import os
import time
from multiprocessing import Pool

def initprocess():
    print("Starting PID: %d" % os.getpid())

def do_work(x):
    print("Doing work in %d" % os.getpid())
    time.sleep(x**2)

if __name__ == '__main__':
    p = Pool(2, initializer=initprocess,maxtasksperchild=1)
    results = p.map(do_work, (1,2), chunksize=1)
History
Date User Action Args
2022-04-11 14:58:18adminsetgithub: 68707
2015-06-27 09:52:20Zahari.Dimsetstatus: open -> closed
2015-06-27 09:22:06Zahari.Dimcreate