bpo-34837: Multiprocessing.Pool API Extension - Pass Data to Workers w/o Globals by seanharr11 · Pull Request #9627 · python/cpython (original) (raw)
Proposing a new kwarg in the __init__()
method of multiprocessing.Pool
named expect_initret
.
This kwarg defaults to False
. When set to True
, the return value of the initializer
function is passed to the function we are applying (i.e. func
in Pool.map(func, ls)
), as a kwarg named initret
.
This PR includes thorough test coverage, and provides backwards compatibility (at least in Python3.x).
See this blog post for example use cases, as well as an initial defense for why this makes the multiprocessing.Pool
API more approachable, to more Python end-users, and augments the library.