<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 30, 2015 at 10:24 AM, Jim J. Jewett <span dir="ltr"><<a href="mailto:jimjjewett@gmail.com" target="_blank">jimjjewett@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I suspect the real problem is that the PEP is really only concerned<br>
with a very specific subtype of coroutine, and these don't quite fit.<br></blockquote></div><br></div><div class="gmail_extra">That's correct. The PEP is concerned with the existing notion of coroutines in Python, which was first introduced by PEP 342: Coroutines via Enhanced Generators. The Wikipedia definition of coroutine (which IIRC is due to Knuth) is quite different and nobody who actually uses the coding style introduced by PEP 342 should mistake one for the other.<br><br> This same notion of "Pythonic" (so to speak) coroutines was refined by PEP 380, which introduced yield from. It was then *used* in PEP 3156 (the asyncio package) for the specific purpose of standardizing a way to do I/O multiplexing using an event loop.<br><br>The basic premise of using coroutines with the asyncio package is that most of the time you can write *almost* sequential code as long as you insert "yield from" in front of all blocking operations (and as long as you use blocking operations that are implemented by or on top of the asyncio package). This makes the code easier to follow than code written "traditional" event-loop-based I/O multiplexing (which is heavy on callbacks, or callback-like abstractions like Twisted's Deferred).<br><br>However, heavy users of the asyncio package (like Yury) discovered some common patterns when using coroutines that were awkward. In particular, "yield from" is quite a mouthful, the coroutine version of a for-loop is awkward, and a with-statement can't have a blocking operation in __exit__ (because there's no explicit yield opcode). PEP 492 proposes a quite simple and elegant solution for these issues. Most of the technical discussion about the PEP is on getting the details right so that users won't have to worry about them, and can instead just continue to write *almost* sequential code when using the asyncio package (or some other framework that offers an event loop integrated with coroutines).<br></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)</div>
</div></div>