Python Interview Questions

Python multiprocessing vs threading vs asyncio

When do you pick multiprocessing, threading, or asyncio?

Why Interviewers Ask This

Senior Python interviews always ask this — answers that know the trade-offs go to the technical round.

How to Answer

  1. 1

    threading: multiple Python threads, share memory, cheap to start. Blocked by GIL for CPU work; good for I/O.

  2. 2

    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.

  3. 3

    asyncio: single-threaded event loop, cooperative via await. Scales to 10k+ sockets on one thread. Requires async-aware libraries.

  4. 4

    Mixed: asyncio for I/O dispatch + ProcessPoolExecutor for CPU hot spots. concurrent.futures unifies the API.

  5. 5

    Gotchas: multiprocessing on Windows uses spawn (no fork) → all args must be picklable; asyncio + blocking call deadlocks the loop.

Sample Answer

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.

Pro Tips

  • 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.

Frequently Asked Questions

Is asyncio always better than threading for I/O?

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.

Can I share objects between processes?

Via multiprocessing.Manager or shared_memory. Both have overhead and serialization costs — prefer message-passing.

Worried About Going Blank in Your Interview?

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