[Tutor] multiprocessing with more than two arguments
markus kossner
m.kossner at tu-bs.de
Thu Oct 15 20:04:15 CEST 2009
Hi,
let's simply start with an example:
#!/usr/bin/python2.6
import numpy as n
def calculate(a,b=3,c=4):
print b
return n.sqrt(n.exp(a*b+c)/n.exp(c)**2)
from multiprocessing import Pool
p = Pool(processes=2)
a_list=range(100000)
result=p.map(calculate,a_list)
This code works qite fine, as long as i yust want to map the
calculate function onto a list of values of a (the first argument of the
function). But what if I want to change the value of b in the compute
function to some other value, than the default one?
I tested things like result=p.map(calculate,a_list,b=5) or
result=p.map(calculate,args=(a_list,b=5)) but nothing works?
Thanks in advance for any help!
Cheers Markus
More information about the Tutor
mailing list