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

Cameron Simpson cs at cskk.id.au
Tue Mar 2 19:01:35 EST 2021


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>


More information about the Python-list mailing list