[Python-ideas] yield from multiple iterables (was Re: The async API of the future: yield-from)

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Oct 19 07:15:33 CEST 2012


Christian Tismer wrote:

> - generators are able to free the stack, when they yield. But when they
>    are active, they use the full stack. At least when I follow the pattern
>    "generator is calling sub-generator".
>    A deeply nested recursion is therefore something to avoid. :-(

Only if yield-from chains aren't optimised the way they
used to be.

In any case, for the application we're talking about here,
the difference will probably not be noticeable.

> But this function that wants to
> switch needs to pass the fact that it wants to switch, plus the target
> somewhere. As I understood it, I would need to yield that to the
> driver function.

You understand incorrectly. In my scheduler, the yields
don't send or receive values at all. Communicating with the
scheduler, for example to tell it to allow another task to
run, is done by calling functions. A yield must be done to
actually allow a switch, but the yield itself doesn't send
any information.

> Do you see it? In my understanding, a switch would not be driven from
> the top and then dispatched upon, but a called function below the
> function to be switched would modify something that leads to a
> switch as a result.

That's pretty much what happens in my scheduler.

> Do you understand, and maybe see where I have the wrong
> brain shortcuts?
> How do you write something composable that scales?

I think you should study my scheduler tutorial. If you can
understand how that works, I think it will answer many of
your questions.

http://www.cosc.canterbury.ac.nz/greg.ewing/python/tasks/

-- 
Greg



More information about the Python-ideas mailing list