[Python-ideas] Cofunctions - Back to Basics

Nick Coghlan ncoghlan at gmail.com
Sun Oct 30 07:11:58 CET 2011


On Sun, Oct 30, 2011 at 4:02 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> 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.

Ouch, I'd missed that completely. Supporting a few assembly hacks in
the core isn't looking so bad at this point ;)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list