[Python-ideas] Cofunctions - A New Protocol

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Nov 2 10:54:56 CET 2011


Nick Coghlan wrote:

> However, as per the previous thread, I don't believe this needs to be
> embedded in the bytecode by the compiler - it could instead be a
> runtime switch in the eval loop, changing the way function calls and
> iteration are handled.

Yes, but I'm no longer sure whether it's such a good idea
to have no special syntax at all to mark a cofunction,
seeing as cofunctionness won't be able to propagate through
C calls, special methods, etc.

By having cofunctions declared in a distinctive way, you
can look at the source and see exactly where the boundary is
between cofunction and non-cofunction code. Without such
markers, when you get an exception because you tried to
suspend in a non-coroutine zone, it may not be obvious
at which point along the call chain you made a mistake.

-- 
Greg



More information about the Python-ideas mailing list