June 2017
Beginner to intermediate
274 pages
6h 49m
English
We can also override default scheduler by passing an explicit event_loop scheduler to the loop keyword-only parameter of the ensure_future function.
f = asyncio.ensure_future(coroutine.example(), loop = scheduler)
Notice that we didn't just pass the coroutine function to ensure_future; we actually invoked it right there inside ensure_future arguments. We did this because the ensure_future function doesn't actually want to refer to the coroutine function. The ensure_future function is only interested in the coroutine object that we saw the coroutine function return earlier. The name ensure_future might seem somewhat odd. If it's used for launching tasks, why is it called that?
The fact of the matter is that launching tasks ...
Read now
Unlock full access