Multithreading is not a prerequisite for async in Python. The default task executor runs in a single thread. So using async APIs should be safe as long as you stick to the single-threaded executor.
Multithreading is not a prerequisite for async in Python. The default task executor runs in a single thread. So using async APIs should be safe as long as you stick to the single-threaded executor.
Good point. Have you seen any major advantage of using async API in practice?
It's... faster for IO bound workloads? That's literally the whole point of async
Async programs can do multiple tasks.
Blocking python can’t.
An example is running multiprocesses and parsing their output and looking for patterns. Async python does this sort of thing well.
If you don’t use `async def` and you are using fastapi it’s easy to accidentally block the event loop.
> it’s easy to accidentally block the event loop.
Can you share a scenario where this would happen?
I have deployed multiple machine learning and data analytics-focused web services, and this has never happened to me.
Well, you can even block event loop in `async def` if you are not careful. When you are using `async def` you need to do all your IO (disk, network) operations asynchronously or your are blocking the event loop.
With a for loop? You probably don't know you are, or just aren't doing anything cpu intensive.