[Python-ideas] More general "for" loop handling

Stephen J. Turnbull stephen at xemacs.org
Sat May 2 15:30:44 CEST 2015


Paul Moore writes:

 >     mypool for item in items:
 >         do_something_here
 >         do_something_else
 >         do_yet_another_thing
 > 
 > I'm assuming that's the OP's intention (it's certainly mine) is that
 > the "mypool for" loop works something like
 > 
 >     def _work(item):
 >         do_something_here
 >         do_something_else
 >         do_yet_another_thing
 >     for _ in mypool.map(_work, items):
 >         # Wait for the subprocesses
 >         pass

I would think that given a pool of processors, the pool's .map method
itself would implement the distribution.  In fact the Pool ABC would
probably provide several variations on the map method (eg, a mapreduce
implementation, a map-to-list implementation, and a map-is-generator
implementation depending on the treatment of results of the _work
computation (if any).

I don't see a need for syntax here.

Aside: Doesn't the "Wait for the subprocesses" belong outside the for
suite?


More information about the Python-ideas mailing list