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

Leopold Toetsch lt at toetsch.at
Thu Sep 30 21:30:17 CEST 2004


Josiah Carlson wrote:
>>It is important to note that Ruby, Parrot (next-generation Perl),
>>and SML-NJ all support this async programming style.  In Python
> 
> 
> For those of us who aren't current on the latest happenings of Ruby,
> Parrot and SML/NJ, it may be convenient for us to hear precisely how
> "async programming style" is done in those languages,

Some clarifications WRT Parrot. Parrot isn't a language, Parrot isn't 
"next-generation Perl". Parrot is a virtual machine that will run Perl6. 
And Parrot is running currently languages like Python, tcl, m4, forth, 
and others more or less completely[1].

Parrot's function calling scheme is CPS. A Python generator function 
gets automatically translated to a coroutine. Returning from a plain 
function is done by invoking a continuation. And you can of course (in 
Parrot assembly) create a continuation store it away and invoke it at 
any time later, which will continue program execution at that point, 
where it should continue.

Please note that that has nothing to do with "aync programming". Its 
just like a GOTO, but w/o limitation where you'll branch to - or almost 
no limitations: you can't cross C-stack boundaries on in other words you 
can't branch to other incarnations of the run-loop. (Exceptions are a 
bit more flexible though, but they still can only jump "up" the C-stack)

Using CPS for function calls implies therefore a non-trivial rewrite of 
CPython, which OTOH and AFAIK is already available as Stackless Python.

Making continuations usable at the language level is a different thing, 
though.

leo

[1] http://www.parrotcode.org - in CVS languages/python. The test b2.py
from the Pie-thon benchmark has two generators (izip, Pi.__iter__), 
which are Parrot coroutines, that's working fine.



More information about the Python-Dev mailing list