yield from () Was: Re: weirdness with list()

Thomas Jollans tjol at tjol.eu
Fri Mar 12 04:41:15 EST 2021


On 03/03/2021 01:01, Cameron Simpson wrote:
> On 02Mar2021 15:06, Larry Martell <larry.martell at gmail.com> wrote:
>> I discovered something new (to me) yesterday. Was writing a unit test
>> for generator function and I found that none of the function got
>> executed at all until I iterated on the return value.
> Aye. Generators are lazy - they don't run at all until you ask for a
> value.
>
> By contrast, this is unlike Go's goroutines, which are busy - they
> commence operation as soon as invoked and run until the first yield
> (channel put, I forget how it is spelled now). This can cause excessive
> CPU utilisation, but it handle for _fast_ production of results. Which
> is a primary goal in Go's design.
>
> Cheers,
> Cameron Simpson <cs at cskk.id.au>

<aside>

I've been learning a bit more JavaScript recently (I know, I know, 
that's no fun) and I think that's the main practical difference between 
JavaScript's async functions, which are scheduled even if nobody awaits 
on them, and Python async functions which are just funky generators and 
therefore scheduled only when somebody awaits their result.

</aside>



More information about the Python-list mailing list