After refactoring, this guarantee will be lost.
This is actually not the case.
Is it possible to call extract_func () in such a way that it runs immediately, as if its code were inline?
This is already the case.
await some_coroutine() means that some_coroutine is most likely to give you control over the contour of the event, but it wonβt do this until it expects the future (for example, some I / O).
Consider the following example:
import asyncio async def coro(): print(1) await asyncio.sleep(0) print(3) async def main(): loop.call_soon(print, 2) await coro() loop = asyncio.get_event_loop() loop.run_until_complete(main())
Notice how 2 is printed between 1 and 3 , as expected.
It also means that you can freeze the event loop by writing this code:
async def coro(): return async def main(): while True: await coro()
In this case, the event loop will never be able to run another task.
source share