[Python-Dev] Minimal 'stackless' PEP using generators? (original) (raw)
Phillip J. Eby pje at telecommunity.com
Mon Aug 23 17:56:04 CEST 2004
- Previous message: [Python-Dev] Minimal 'stackless' PEP using generators?
- Next message: [Python-Dev] Minimal 'stackless' PEP using generators?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
At 11:39 AM 8/23/04 -0400, Clark C. Evans wrote:
I just read the thread 'Stackless Python' in June 2004 on python-dev and was wondering if you'd comment on a simpler cooperative mechanism, via a small hack to generators:
1. The PEP would introduce a new 'builtin' class called 'Cooperate' 2. Generator semantics would be altered so that 'yield X', where X is an instance of Cooperate, would automagically propigate to the outer-most non-generator.
Perhaps you mean "inner-most"?
With these two changes, the "lower" function could be an async reactor like those found in Twisted, or async core. While the result isn't true coutines, it would be a huge improvement for those who would like to do async coding. I've done something similar with Twisted called Flow [1] and it works well, with the exception of being a painful syntax hack and being quite slow. If this was moved into Python's core, we'd get most of the advantages of coroutines without the full cost.
Thoughts?
It doesn't seem to me to actually help anything. You can already do this using a simple wrapper object that maintains a stack of active generators, as I do in 'peak.events'.
I was hoping that you had actually come up with a solution for the more complex problem of suspending non generator functions, in a way that would work with CPython. :(
- Previous message: [Python-Dev] Minimal 'stackless' PEP using generators?
- Next message: [Python-Dev] Minimal 'stackless' PEP using generators?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]