2 ms·
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 s
by Hackbraten 2y ago
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.
- ashishb 2y agoGood point. Have you seen any major advantage of using async API in practice?
- phyrex 2y agoIt's... faster for IO bound workloads? That's literally the whole point of async
- ibash 2y agoIf you don’t use `async def` and you are using fastapi it’s easy to accidentally block the event loop.
- ashishb 2y ago> 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.
- winrid 2y agoWith a for loop? You probably don't know you are, or just aren't doing anything cpu intensive.
- chamoda 2y agoWell, 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.
- deleted 2y ago[deleted]
- andrewstuart 2y agoAsync 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.