When do you pick multiprocessing, threading, or asyncio?
Senior Python interviews always ask this — answers that know the trade-offs go to the technical round.
threading: multiple Python threads, share memory, cheap to start. Blocked by GIL for CPU work; good for I/O.
multiprocessing: separate processes, each with own interpreter and GIL. True parallelism for CPU work. Overhead: start time (fork/spawn), inter-process data passing via pickle.
asyncio: single-threaded event loop, cooperative via await. Scales to 10k+ sockets on one thread. Requires async-aware libraries.
Mixed: asyncio for I/O dispatch + ProcessPoolExecutor for CPU hot spots. concurrent.futures unifies the API.
Gotchas: multiprocessing on Windows uses spawn (no fork) → all args must be picklable; asyncio + blocking call deadlocks the loop.
Three-way decision. CPU-bound crunching: multiprocessing or native (numpy/numba) — threading won't parallelize because of the GIL. I/O-bound with <100 concurrent ops: threads are fine, simple code. I/O-bound with thousands of concurrent sockets: asyncio — an event loop scales further than a thread per connection. The mixed case is common: asyncio dispatches I/O, and for CPU hot spots I run_in_executor to a ProcessPoolExecutor. Gotchas: any sync blocking call inside an asyncio handler freezes the whole loop — wrap it in to_thread. multiprocessing has its own quirks — on Windows everything is pickled and re-launched, so capturing closures don't survive. I default to asyncio for new services, multiprocessing for data-pipeline style CPU work.
asyncio.run() + one event loop per process — don't mix loops across threads naively.
Process pools size: roughly os.cpu_count(); thread pools can be larger if tasks are I/O-heavy.
HireMe AI (即答侠) has a one-page decision matrix that interviewers visibly like.
At low concurrency, threading is fine and lets you use sync libraries. asyncio wins when you need tens of thousands of concurrent I/Os or non-blocking back-pressure.
Via multiprocessing.Manager or shared_memory. Both have overhead and serialization costs — prefer message-passing.
HireMe AI listens to your interview in real-time, detects questions, and generates instant answer suggestions — so you never freeze up again.
Try HireMe AI Free