Adding a Par construct to Python?

Paul Boddie paul at
Wed May 20 11:25:15 EDT 2009

On 20 Mai, 15:01, Iain King <iaink... at> wrote:
> I was going to write something like this, but you've beat me to it :)
> Slightly different though; rather than have pmap collate everything
> together then return it, have it yield results as and when it gets
> them and stop iteration when it's done, and rename it to par to keep
> the OP happy and you should get something like what he initially
> requests (I think):
> total = 0
> for score in par(f, data):
>     total += score

It depends on whether you want the outputs to correspond to the inputs
in the resulting sequence. If pmap is supposed to behave like map, you
want the positions of each input and corresponding output to match. As
I wrote earlier, in pprocess you distinguish between these cases by
employing maps (for input/output correspondence) and queues (for
"first ready" behaviour).

I don't recall whether the Map class in pprocess blocks for all the
data to be returned, or whether you can consume any outputs that are
at the start of the output sequence (and then block until output
arrives at the next available position), but this would be a logical


More information about the Python-list mailing list