[Python-ideas] Yield-From Example 2: Scheduler
rhamph at gmail.com
Thu Feb 19 23:49:46 CET 2009
On Thu, Feb 19, 2009 at 2:32 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> The yield-from statement makes it possible to write thread code using
> generators almost the same way as you would write ordinary code.
> Whether it's any easier or clearer than using things like yield
> Call(g(x)) and yield Return(x) is debatable. However, I think this
> example does show that the implementation of a generator-based
> scheduler can be very clean and simple when yield-from is available,
> and if it is suitably optimised, probably more efficient as well.
You don't use plain "yield" except internally, so you don't even need
"yield Call(g(x))". You only need "yield g(x)" and your scheduler can
assume it's a generator. "yield from g(x)" provides no value to the
user (it's simply a longer spelling of a same thing).
The debatable value to the scheduler is a one time cost. It'd have to
be quite massive to warrant imposing new syntax on everybody else.
The fact that such schedulers already exist is a pretty strong
argument that it's not a massive cost.
Adam Olsen, aka Rhamphoryncus
More information about the Python-ideas