[Python-Dev] PEP 334 - Simple Coroutines via SuspendIteration

Clark C. Evans cce at clarkevans.com
Thu Sep 30 17:47:22 CEST 2004


To distill this request to a sentence:

   I would like syntax-level support in Python for a Continuation
   Passing Style (CPS) of code execution.

It is important to note that Ruby, Parrot (next-generation Perl),
and SML-NJ all support this async programming style.  In Python
land, the Twisted framework uses this style via its Deferred
mechanism. This isn't a off-the-wall request.  I currently think
that a generator syntax would be the best, and this proposal is for
further work via defining a SuspendIterator semantics.  However, I'm
not tied to this implementation.  A pre-parser which made Deferred
object handling nicer could also work, or any other option that
provides an intuitive syntax for CPS in Python.

The hoops that Twisted has to jump-through to wrap Exceptions for
use in a Deferred processing chain, and also the (completely
necessary but yet) convoluted ways of combining Deferreds is, IMHO,
a direct result of lack of support for CPS in Python.  These items
have a huge impact application program readability and maintenance.
Clean syntax-level support for CPS in Python would be a boon for
application developers.

Best,

Clark


More information about the Python-Dev mailing list