[Tutor] multiprocessing with more than two arguments

Kent Johnson kent37 at tds.net
Thu Oct 15 21:44:18 CEST 2009


On Thu, Oct 15, 2009 at 2:04 PM, markus kossner <m.kossner at tu-bs.de> wrote:
> 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?

Pool.map() seems to only support a single parameter. I think you will
have to redefine calculate() to take for example a dict parameter
containing the actual arcuments.

Kent


More information about the Tutor mailing list