In python, is there a simple way to pass 1+ args to pool.map -
i want use pool.map simplify concurrency in scripts , find same question below link, not concise method issue.
python multiprocessing pool.map multiple arguments
from multiprocessing.dummy import pool threadpool def run_multiple_args(tuple_args): args_1 = tuple_args[0] args_2 = tuple_args[1] print args_1, args_2 pool = threadpool(2) arg_list = [(1,2), (4,8)] pool.map(func=run_multiple_args, iterable=arg_list) pool.close() pool.join()
i want use def run_multiple_args(args_1, args_2): replace tuple_args.
no 3rd party lib, less code more better. idea?
you can use lambda unpack argument tuple:
from multiprocessing.dummy import pool threadpool def run_multiple_args(args_1, args_2): print args_1, args_2 pool = threadpool(2) arg_list = [(1,2), (4,8)] pool.map(func=lambda args: run_multiple_args(*args), iterable=arg_list) # <-- see here pool.close() pool.join()
Comments
Post a Comment