multiprocess passing arguments double asterisks

Thomas Nyberg tomuxiong at gmx.com
Mon Oct 24 13:07:12 EDT 2016


On 10/24/2016 12:45 PM, pic8690 at gmail.com wrote:
> Thanks for the reply.
>
> The code snippet given by Peter is not very clear
>
> I would like to multiprocess a function which is written in python of the form bar(**kwargs) which returns a value.  This example does not return anything
>
> Would you please use my example for the map function?
>
> I appreciate your help,
>
I'm honestly not totally sure what you want to do. However, say you want 
to do the following (btw this is basically what Dennis said i nhis last 
email, but maybe I can help clarify):

	kwargs = {'param1': val1, 'param2': val2})

Then you'd like to have the following two operations performed in 
separate processes:

	bar(param1=val1)
	bar(param2=val2)

In that case, I guess I would do something like the following. First 
define bar_wrapper as follows (*I haven't tested any code here!):

def bar_wrapper(pair):
	key, val = pair
	return bar(**{key: val})

Then I would probably do something like

map(bar_wrapper, kwargs.items())

I.e. basically what I'm doing is taking the key-val pairs and producing 
a list of them (as tuples). This is something that you can apply map 
too, but not with the original function. So then the wrapper function 
converts the tuple back to what you want originally.

Hopefully I'm understanding correctly and hopefully this helps.

Cheers,
Thomas



More information about the Python-list mailing list