Concurrency and parallelism

Concurrency is dealing with many things at once: start a download, and while it waits, start another. Parallelism is doing many things at the same instant, on several CPU cores.

What your program spends its time on decides which you need:

  • I/O-bound: mostly waiting for the network, a disk or a database. Concurrency helps, because the waiting overlaps. Use asyncio or threads.
  • CPU-bound: mostly computing. Only parallelism helps. Use processes.

The surprise is the GIL (global interpreter lock). In standard CPython, only one thread runs Python code at a time. Threads still help with waiting, because a thread lets go of the GIL while it waits. They don't make number crunching faster. Python 3.13 added an optional free-threaded build without the GIL, but most installs still have it.

Interviewers often ask "threads or processes?". Answer with "is it I/O-bound or CPU-bound?" first.

Run it to see the choice as code, and whether your Python has the GIL.