async vs thread

September 6, 2025


one thing i had a ton of issues with in my code quality was not using modern python typing preferences - list, dict over List, Dict in 3.9+. the root of that is because claude code is just trained on a bunch of old code, and using claude code extensively, i got flamed in my review. which was very helpful because now i know better. i love making mistakes, even though it comes at the expense of my prideβ€”that's something i should let go of more often.

also learned about the benefits of asyncio over threadpool in python. essentially it uses a lot less memory because there's only one thread managing the event loop, versus threadpool which spawns multiple threads.

ASYNCIO (Single Thread) [Event Loop] β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β–Ό β–Ό β–Ό β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Task 1 β”‚ β”‚ Task 2 β”‚ β”‚ Task 3 β”‚ β”‚ [API1] β”‚ β”‚ [API2] β”‚ β”‚ [API3] β”‚ ← all tasks β”‚ waiting β”‚ β”‚ waiting β”‚ β”‚ waiting β”‚ started β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ instantly Memory: ~1 thread, minimal overhead
THREADPOOL (Multiple Threads) β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Thread 1 β”‚ Thread 2 β”‚ Thread 3 β”‚ Thread 4 β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ [API1] β”‚ [API2] β”‚ [API3] β”‚ [API4] β”‚ ← 4 tasks β”‚ waiting β”‚ waiting β”‚ waiting β”‚ waiting β”‚ running β”‚ β”‚ β”‚ β”‚ β”‚ β”‚ [API5] β”‚ [API6] β”‚ idle β”‚ idle β”‚ ← tasks 5-6 β”‚ waiting β”‚ waiting β”‚ β”‚ β”‚ must wait β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Memory: ~4 threads, higher overhead per thread

Previous:

linting