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

梦想的初衷 提交于 2019-11-30 11:35:56

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

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

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)])
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!