In the Python multiprocessing
library, is there a variant of pool.map
which supports multiple arguments?
text = "test"
def
Using Python 3.3+ with pool.starmap():
from multiprocessing.dummy import Pool as ThreadPool
def write(i, x):
print(i, "---", x)
a = ["1","2","3"]
b = ["4","5","6"]
pool = ThreadPool(2)
pool.starmap(write, zip(a,b))
pool.close()
pool.join()
Result:
1 --- 4
2 --- 5
3 --- 6
You can also zip() more arguments if you like: zip(a,b,c,d,e)
In case you want to have a constant value passed as an argument you have to use import itertools
and then zip(itertools.repeat(constant), a)
for example.