| Store | Cart

Re: [Python-Dev] PEP 492: What is the real goal?

From: Guido van Rossum <gui...@python.org>
Thu, 30 Apr 2015 10:55:08 -0700
On Thu, Apr 30, 2015 at 10:24 AM, Jim J. Jewett <jimj...@gmail.com>
wrote:

> 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.>

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.

 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.

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).

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).

-- 
--Guido van Rossum (python.org/~guido)

_______________________________________________
Python-Dev mailing list
Pyth...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/python-dev-ml%40activestate.com

Recent Messages in this Thread
Jim J. Jewett Apr 29, 2015 05:43 pm
Paul Moore Apr 29, 2015 06:26 pm
Yury Selivanov Apr 29, 2015 06:42 pm
Paul Moore Apr 29, 2015 07:19 pm
Yury Selivanov Apr 29, 2015 07:42 pm
Skip Montanaro Apr 29, 2015 08:14 pm
Nathaniel Smith Apr 29, 2015 08:19 pm
Guido van Rossum Apr 29, 2015 08:30 pm
Greg Ewing Apr 30, 2015 06:53 am
Paul Sokolovsky Apr 30, 2015 07:58 am
Paul Moore Apr 29, 2015 10:02 pm
Greg Ewing Apr 30, 2015 06:35 am
Arnaud Delobelle Apr 30, 2015 08:50 am
Oscar Benjamin May 05, 2015 04:01 pm
Yury Selivanov May 05, 2015 04:48 pm
Guido van Rossum May 05, 2015 07:24 pm
Oscar Benjamin May 06, 2015 09:20 am
Paul Sokolovsky Apr 29, 2015 09:06 pm
Greg Ewing Apr 30, 2015 12:08 pm
Paul Moore Apr 30, 2015 06:52 pm
Greg Ewing Apr 30, 2015 05:39 am
Paul Moore Apr 30, 2015 08:17 am
Jim J. Jewett Apr 30, 2015 05:24 pm
Guido van Rossum Apr 30, 2015 05:55 pm
Guido van Rossum Apr 28, 2015 09:49 pm
Yury Selivanov Apr 28, 2015 11:26 pm
Ethan Furman Apr 28, 2015 11:55 pm
Guido van Rossum Apr 29, 2015 12:04 am
Ethan Furman Apr 29, 2015 05:18 am
Greg Ewing Apr 29, 2015 09:12 am
Yury Selivanov Apr 29, 2015 05:00 am
Greg Ewing Apr 29, 2015 09:13 am
Yury Selivanov Apr 29, 2015 02:01 pm
Greg Ewing Apr 29, 2015 10:46 pm
Yury Selivanov Apr 29, 2015 10:58 pm
Greg Ewing Apr 29, 2015 09:12 am
Yury Selivanov Apr 29, 2015 02:16 pm
Greg Apr 29, 2015 03:59 am
Yury Selivanov Apr 29, 2015 04:10 am
Greg Ewing Apr 29, 2015 09:13 am
Yury Selivanov Apr 29, 2015 02:18 pm
Greg Ewing Apr 29, 2015 09:12 am
Yury Selivanov Apr 29, 2015 02:29 pm
Messages in this thread