Python multiprocessing pool.map for multiple arguments
Question: In the Python multiprocessing library, is there a variant of pool.map which
support multiple arguments?

    
    
    text = "test"
    def harvester(text, case):
        X = case[0]
        return text+ str(X)
    
    if __name__ == '__main__':
        pool = multiprocessing.Pool(processes=6)
        case = RAW_DATASET
        pool.map(harvester(text,case),case, 1)
        pool.close()
        pool.join()
    


Answer: > is there a variant of pool.map which support multiple arguments?

Python 3.3 includes [`pool.starmap()`
method](http://docs.python.org/dev/library/multiprocessing.html#multiprocessing.pool.Pool.starmap):

    
    
    #!/usr/bin/env python3
    from functools import partial
    from itertools import repeat
    from multiprocessing import Pool, freeze_support
    
    def func(a, b):
        return a + b
    
    def main():
        a_args = [1,2,3]
        second_arg = 1
        with Pool() as pool:
            L = pool.starmap(func, [(1, 1), (2, 1), (3, 1)])
            M = pool.starmap(func, zip(a_args, repeat(second_arg)))
            N = pool.map(partial(func, b=second_arg), a_args)
            assert L == M == N
    
    if __name__=="__main__":
        freeze_support()
        main()
    

For older versions:

    
    
    #!/usr/bin/env python2
    import itertools
    from multiprocessing import Pool, freeze_support
    
    def func(a, b):
        print a, b
    
    def func_star(a_b):
        """Convert `f([1,2])` to `f(1,2)` call."""
        return func(*a_b)
    
    def main():
        pool = Pool()
        a_args = [1,2,3]
        second_arg = 1
        pool.map(func_star, itertools.izip(a_args, itertools.repeat(second_arg)))
    
    if __name__=="__main__":
        freeze_support()
        main()
    

### Output

    
    
    1 1
    2 1
    3 1
    

Notice how
[`itertools.izip()`](https://docs.python.org/2.7/library/itertools.html#itertools.izip)
and
[`itertools.repeat()`](https://docs.python.org/2.7/library/itertools.html#itertools.repeat)
are used here.

Due to [the bug mentioned by @unutbu](http://bugs.python.org/issue5228) you
can't use
[`functools.partial()`](http://docs.python.org/library/functools.html#functools.partial)
or similar capabilities on Python 2.6, so the simple wrapper function
`func_star()` should be defined explicitly. See also [the
workaround](http://paste.pocoo.org/show/351774/) [suggested by
`uptimebox`](http://bugs.python.org/issue5228#msg130548).

