I have a function that takes one argument, saves a file to a fixed directory, and returns None
. I want to use multiproccessing.Pool.map
to execute this function in parallel over many arguments. Will this actually work for functions that don't return a value?
I'm asking because the documentation says that Pool.map
is equivalent to the built-in map
, but map(fcn, arg_list)
does not actually execute the function calls until its results are iterated over. In my case there is no point iterating over the results, which are None
.
Is the documentation incorrect in this regard?
I'd say the docs are a little out of date. The built-in map
became an iterable along the way, but Pool.map
(still) returns a list. So the multiprocessing
machinery is iterating over the results returned, in order to build that list (yes, they all happen to be None
in your case, but the list is built regardless of what the results are).
You don't need to iterate over that list too, but I suggest doing so anyway: then the code will be robust against, say, a future release that may change Pool.map()
too to return an iterable.