how do I use key word arguments with python multiprocessing pool apply_async how do I use key word arguments with python multiprocessing pool apply_async python python

how do I use key word arguments with python multiprocessing pool apply_async


Pass the keyword args in a dictionary (and the positional arguments in a tuple):

pool.apply_async(test, (t,), dict(arg2=5))


original answer: python multiprocessing with boolean and multiple arguments

apply_async has args and kwds keyword arguments which you could use like this:

res = p.apply_async(testFunc, args=(2, 4), kwds={'calcY': False})


Janne's answer didn't work for me in python 2.7.11 (not sure why).The function test() was receiving the key (arg2), not the value (5).

I fixed this by creating a wrapper around test:

def test2(argsDict):    test(**argsDict)

Then calling

pool.apply_async(test2, (t,), [dict(arg2=5)])