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

Guido van Rossum guido at python.org
Thu Apr 30 19:31:40 CEST 2015


Ah. But 'async for' is not meant to introduce parallelism or concurrency.
It is only meant to be able to insert specific places during a sequential
iteration where a coroutine's stack can be suspended. The primitives
proposed by PEP 492 don't introduce new ways to spell concurrency -- for
that you would need things like asyncio.gather().

If you want to introduce ways to spell concurrency directly in the language
you'll have to write and defend your own PEP.

PEP 492 is only meant to make code easier to read and write that's already
written to use coroutines (e.g. using the asyncio library, but not limited
to that).

On Thu, Apr 30, 2015 at 10:13 AM, Todd <toddrjen at gmail.com> wrote:

>
>
> On Thu, Apr 30, 2015 at 6:45 PM, Paul Moore <p.f.moore at gmail.com> wrote:
>
>> On 30 April 2015 at 17:03, Stefan Behnel <stefan_ml at behnel.de> wrote:
>> > Steven D'Aprano schrieb am 30.04.2015 um 13:36:
>> >> "async for" hasn't proven itself yet, and you are already looking to
>> >> generalise it? Shouldn't it prove itself as not a mistake first?
>> >
>> > Also, it should be quite possible to achieve what the OP proposed with
>> > "async for" since it's in no way limited to the way asyncio handles
>> things.
>> > "async for" is a bit of a badly named feature, but that's intended in
>> order
>> > to match what people would know from other programming languages.
>>
>> Could you explain how?
>>
>> Specifically, what's the translation of
>>
>> from multiprocessing import Pool
>>
>>     mypool = Pool(10, maxtasksperchild=2)
>>
>>     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
>>
>
> Yes, thank you, that is exactly what I intended.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150430/2f121e37/attachment.html>


More information about the Python-ideas mailing list