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

Joao S. O. Bueno jsbueno at python.org.br
Thu Apr 30 20:31:04 CEST 2015


On 30 April 2015 at 06:48, Todd <toddrjen at gmail.com> wrote:
> Looking at pep 492, it seems to me the handling of "for" loops has use
> outside of just asyncio.  The primary use-case I can think of is
> multiprocessing and multithreading.
>
> For example, you could create a multiprocessing pool, and let the pool
> handle the items in a "for" loop, like so:
>
>     from multiprocessing import Pool
>
>     mypool = Pool(10, maxtasksperchild=2)
>
>     mypool for item in items:
>         do_something_here
>         do_something_else
>         do_yet_another_thing



While the idea is cool, maybe the original "for" is quite enough for
doing that -
as can be seen in this real-world (if simple) package:

https://github.com/npryce/python-parallelize
---------------
import os
from parallelize import parallelize

for i in parallelize(range(100)):
    print(os.getpid(), i)


More information about the Python-ideas mailing list