Generators versus Coroutines

Nick Patavalis npat at efault.net
Mon Aug 16 21:19:44 CEST 2004


On 2004-08-15, Michael Sparks <zathras at thwackety.com> wrote:
>
>> For me it would be *tremendously* usefull if one could yield across
>> multiple levels of function calls. If this was supported, then most
>> uses of O/S treads could be replaced by generators.
>

I didn't knew about Stackless or Greenlets. I will take a look at
this, thanks!

>
> Indeed using the new decorator syntax you could probably simplify this to:
>
> def foobar(i): Yield(i)
>
> @generator
> def g(n):
>     for i in range(n):
>         foobar(i)
>

Another excellent use for decorators!

/npat



More information about the Python-list mailing list