Asyncio -- delayed calculation

Ian Kelly ian.g.kelly at gmail.com
Thu Dec 1 14:09:45 EST 2016


On Thu, Dec 1, 2016 at 12:53 AM, Christian Gollwitzer <auriocus at gmx.de> wrote:
> well that works - but I think it it is possible to explain it, without
> actually understanding what it does behind the scences:
>
> x = foo()
> # schedule foo for execution, i.e. put it on a TODO list

This implies that if you never await foo it will still get done at
some point (e.g. when you await something else), which for coroutines
would be incorrect unless you call ensure_future() on it.

Come to think about it, it would probably not be a bad style rule to
consider that when you call something that returns an awaitable, you
should always either await or ensure_future it (or something else that
depends on it). Barring the unusual case where you want to create an
awaitable but *not* immediately schedule it.


More information about the Python-list mailing list