-
Book Overview & Buying
-
Table Of Contents
Mastering Python 2E - Second Edition
By :
Working with asyncio will require active thought throughout most of your development process. Besides asyncio.run() and similar methods, there is no way to run an async def from synchronous code. This means that every intermediate function between your main async def and the code that needs asyncio will have to be async as well.
You could make a synchronous function return a coroutine so one of the parent functions can run it within an event loop. But that usually results in a very confusing execution order of the code, so I would not recommend going down that route.
In short, this means that any asyncio project you try with the asyncio debug setting enabled is good practice. We can create a few challenges, however:
asyncio base class that automatically registers all instances for easy closing/destructuring when you are doneasyncio wrapper class for a synchronous process such as file or network operations using executors...