[Python-Dev] Tricky way of of creating a generator via a comprehension expression

Antoine Pitrou antoine at python.org
Thu Nov 23 07:48:43 EST 2017


Le 23/11/2017 à 13:42, Ivan Levkivskyi a écrit :
> 
> Great, so I open this page and see this code:
> 
> results = []
> for future in list_of_futures:
>     results.append(yield future)
> 
> Interesting, why don't they use a comprehension for this and instead
> need to invent a whole `tornado.gen.multi` function?

1) because it schedules the yielded coroutines in parallel (the "for"
loop isn't strictly equivalent, as AFAIU it would schedule the
coroutines serially)

2) because it accepts an optional argument to quiet some exceptions

Regards

Antoine.


More information about the Python-Dev mailing list