4 ms·
I agree that especially within the standard context of python and its syntax, async seems weird (because it's sprinkled into an existing paradigm). The best me
by uniqueuid 4y ago
I agree that especially within the standard context of python and its syntax, async seems weird (because it's sprinkled into an existing paradigm).
The best mental model for me always was to think: Here's an await, that means "interpreter, go and do something else that's currently waiting while this is not done yet."
And that's all about IO, because what you can wait on is essentially IO.
By the way, I really wish there was a better story to executors in async python. To think we still have the same queue/pickle-based multiprocessing to send async tasks to another core is kind of sad. Hoping for 3.12 and beyond there.
[edit] one really neat example that helped me get asyncio was Guido van Rossum's crawler in 500 lines of python [1]. A lot of the syntax is deprecated now, but it's still a great walk-through
[1] http://aosabook.org/en/500L/a-web-crawler-with-asyncio-coroutines.html http://aosabook.org/en/500L/a-web-crawler-with-asyncio-corou...