[Python-ideas] Cofunctions - Back to Basics
Greg Ewing
greg.ewing at canterbury.ac.nz
Mon Oct 31 07:54:32 CET 2011
Nick Coghlan wrote:
> It means we basically have two potential paths forward:
>
> 1. Stackless Python (aka greenlets).
> Pros: known to work for a large number of use cases
> Cons: need to define a mechanism to declare that the C stack is
> being used in a "coroutine friendly" fashion
>
> 2. Implicit creation of generator-style suspendable frames
> Pros: shouldn't need assembly level hackery
> Cons: effectively requires duplication of every C level type slot
> with a coroutine friendly equivalent that supports suspension
Or maybe there's a third way:
3. Recognise that, today, some people *are* using generators
to do coroutine-like programming and finding it a useful
technique, despite all of its limitations, and consider
ways to make it easier, even if we can't remove all of
those limitations.
It seems to me that the inability to suspend from within a
special method is not likely to be a problem very often in
practice.
Inability to use generators as generators in a coroutine
environment may be more serious, since it's quite likely
people will want to e.g. use a for-loop to iterate over
lines being read from a socket, and suspend while waiting
for data to arrive.
I think that particular problem could be solved, given
some more thought. The question is, would it be worth the
effort?
--
Greg
More information about the Python-ideas
mailing list