[Python-Dev] PEP 492: What is the real goal?
Jim J. Jewett
jimjjewett at gmail.com
Thu Apr 30 19:24:27 CEST 2015
On Wed, Apr 29, 2015 at 2:26 PM, Paul Moore <p.f.moore at gmail.com> wrote:
> On 29 April 2015 at 18:43, Jim J. Jewett <jimjjewett at gmail.com> wrote:
>> So? PEP 492 never says what coroutines *are* in a way that explains
>> why it matters that they are different from generators.
...
> Looking at the Wikipedia article on coroutines, I see an example of
> how a producer/consumer process might be written with coroutines:
>
> var q := new queue
>
> coroutine produce
> loop
> while q is not full
> create some new items
> add the items to q
> yield to consume
>
> coroutine consume
> loop
> while q is not empty
> remove some items from q
> use the items
> yield to produce
>
> (To start everything off, you'd just run "produce").
>
> I can't even see how to relate that to PEP 429 syntax. I'm not allowed
> to use "yield", so should I use "await consume" in produce (and vice
> versa)?
I think so ... but the fact that nothing is actually coming via the
await channel makes it awkward.
I also worry that it would end up with an infinite stack depth, unless
the await were actually replaced with some sort of framework-specific
scheduling primitive, or one of them were rewritten differently to
ensure it returned to the other instead of calling it anew.
I suspect the real problem is that the PEP is really only concerned
with a very specific subtype of coroutine, and these don't quite fit.
(Though it could be done by somehow making them both await on the
queue status, instead of on each other.)
-jJ
More information about the Python-Dev
mailing list