how do I use key word arguments with python multiprocessing pool apply_async -
i'm trying grips pythons multiprocessing module, apply_async method of pool. i'm trying phone call function arguments , keyword arguments. if phone call function without kwargs it's fine when seek add together in keyword argument get: typeerror: apply_async() got unexpected keyword argument 'arg2' below test code i'm running
#!/usr/bin/env python import multiprocessing time import sleep def test(arg1, arg2=1, arg3=2): sleep(5) if __name__ == '__main__': pool = multiprocessing.pool() t in range(1000): pool.apply_async(test, t, arg2=5) pool.close() pool.join() how can phone call function accepts keyword arguments?
pass keyword args in dictionary (and positional arguments in tuple):
pool.apply_async(test, (t,), dict(arg2=5)) python multiprocessing threadpool
No comments:
Post a Comment