[Python-Dev] PEP 380 (yield from a subgenerator) comments
Greg Ewing
greg.ewing at canterbury.ac.nz
Fri Mar 27 04:08:07 CET 2009
Antoine Pitrou wrote:
> There seems to be a misunderstanding as to how generators
> are used in Twisted. There isn't a global "trampoline" to schedule generators
> around. Instead, generators are wrapped with a decorator (*) which collects each
> yielded value (it's a Deferred object) and attaches to it a callback which
> resumes (using send()) the execution of the generator whenever the Deferred
> finally gets its value.
This sounds like an architecture that was developed to
work around the lack of anything like yield-from in the
language.
You can't expect to improve something like that by
stuffing yield-from into the existing framework, because
the point of yield-from is to render the framework
itself unnecessary. To take full advantage of it, you
need to step back and re-design the whole thing in
a different way.
In the case of Twisted, I expect the new design would
look a lot like my generator scheduling example.
--
Greg
More information about the Python-Dev
mailing list