[Python-ideas] Cofunctions - Back to Basics

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Oct 30 07:02:36 CET 2011


Nick Coghlan wrote:
> However, I think we still potentially have a
> problem due to the overloading of a single communications channel
> (i.e. using 'yield' both to suspend the entire coroutine, but also to
> return values to the next layer out).

Bugger, you're right.

With sufficient cleverness, I think it could be made
to work, but it occurs to me that this is really a
special case of a more general problem. For example,
an __add__ method implemented in Python wouldn't be
able to suspend a coroutine.

So we would be over-promising somewhat if we claimed
that *any* pure-python code could be suspended with
'coyield'. It would be more like "any pure-python
code, as long as no special method call is involved
anywhere along the call chain".

Fixing that would require making some rather extensive
changes. Either every type slot would need to get a
cocall counterpart, or their signatures would need an
argument to indicate that a cocall was being made,
or something like that.

-- 
Greg



More information about the Python-ideas mailing list