[Python-ideas] PEP 3156 - Coroutines are more better (original) (raw)

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Jan 24 03:14:31 CET 2013


On 24/01/13 14:57, Dustin J. Mitchell wrote:

One of the things that's been difficult for some time in Twisted is writing clients in such a way that they reliably finish.

I think I'm going to wait and see what the coroutine-level features of tulip turn out to be like before saying much more.

It seems to me that many of the problems we're arguing about here simply don't exist in coroutine-land. For example, if you can write something like

yield from create_http(yield from create_tcp(host, port))

and creation of the transport fails and raises an exception, then create_http never gets called, so you won't waste any effort creating an unused protocol object.

Likewise, if the main loop of your protocol consists of a Task that reads asynchronously from the transport, then (as long as you haven't done anything blatantly stupid) you know it will eventually return when the connection gets closed.

If I were designing all this, I think I would have made coroutines the default way of dealing with everything above the event loop layer, and provide callback wrappers for those that like to do things that way. Building an entire callback-based protocol stack seems like going about it the hard way.

-- Greg



More information about the Python-ideas mailing list