multiprocess passing arguments double asterisks

Thomas Nyberg tomuxiong at gmx.com
Sun Oct 23 08:51:58 EDT 2016


On 10/23/2016 03:12 AM, pic8690 at gmail.com wrote:
> import <span class="highlight" style="padding-left: 0px; padding-right: 0px;">multiprocess</span>ing as mp
>
> def bar(**kwargs):
>    for a in kwargs:
>       print a,kwargs[a]
>
> arguments={'name':'Joe','age':20}
> p=mp.Pool(processes=4)
> p.map(bar,**arguments)
> p.close()
> p.join()

What are you trying to do? The map method is similar to the map built-in:

	https://docs.python.org/2/library/multiprocessing.html#multiprocessing.pool.multiprocessing.Pool.map
	https://docs.python.org/2/library/functions.html#map

map(function, iterable, ...)
Apply function to every item of iterable and return a list of the results...

You can't apply it to keyword arguments like this. There are some 
different SO threads talking about this sort of thing:

	http://stackoverflow.com/questions/13499824/using-python-map-function-with-keyword-arguments
	http://stackoverflow.com/questions/10212445/python-map-list-item-to-function-with-arguments
	http://stackoverflow.com/questions/16874244/python-map-and-arguments-unpacking

Maybe those (especially the last one) are helpful.

Cheers,
Thomas



More information about the Python-list mailing list