watch this The wheels are turning, slowly turning. home
Daddy, What Is A Coroutine? 2005-12-19


Some people have gotten the idea that Python 2.5 will have coroutines.




Let me just be blunt. Python 2.5 will not have coroutines. PEP 342 even says so. Coroutines can be switched between regardless of their position in the call stack. Python’s generators can only switch to the frame directly above them in the stack. The PEP suggests that it will allow coroutines to be implemented using a trampoline (with which, by the way, Guido doesn’t even think anyone important will bother). Well, this may be true in the strictest sense - PEP 342 won’t prevent you from implementing such a trampoline, but it is already possible to do so.




Don’t misinterpret: PEP 342 corrects a long-standing mistake in Python’s generators (yield definitely makes sense as an expression). Insofar as it corrects a syntactic inequity in the language, this is a fine PEP. It just has nothing to do with coroutines.