Saturday, June 25, 2005

PEP 342 -- Coroutines via Enhanced Generators

PEP 342 -- Coroutines via Enhanced Generators. The name pretty much says it all. This is syntactical support for doing in a "forwards" way, what Twisted does in a "backwards" way, what Stackless Python does by reimplementing the Python interpreter, and Greenlets do by messing with the C stack in assembly. (And peak.events does with a magic function and some syntactic ugliness.)

The PEP was originally written by Guido, but after I implemented the important parts of his draft (and his other generator enhancements from PEP 343), he asked me to take co-authorship. Since then, I've fleshed out the "Motivation" and "Examples" sections to help show what these (proposed) new features can really do.

Happily, this proposal is no longer speculative as to whether it can be implemented; last weekend I put together a patch on Sourceforge that implements the functionality shown now in the PEP. So, the only real question is whether there's any backlash on comp.lang.python or the Python-Dev list, which I don't really expect. Hopefully, this or something like it will find its way into Python 2.5.

(And while you're reading PEPs, it's probably also worth taking a glance at PEP 343 too, if you haven't already. It's a nice way to encapsulate try-finally usage patterns as reusable objects.)

<< Jun 05: CPAN Goodies for all
>> Jul 01: It's log, log, log

^^ Home