Quiz

Threads, Processes & the GIL

Python gives you three main ways to do things "at once":

Tool Best for Notes
asyncio Lots of I/O waits One thread; you choose where to switch (await); needs async libraries
threads (threading, ThreadPoolExecutor) I/O with ordinary blocking libraries The OS switches threads at any moment
processes (multiprocessing, ProcessPoolExecutor) CPU-heavy work Separate interpreters on separate cores; data must be copied between them

The GIL

Standard CPython has a Global Interpreter Lock (GIL): only one thread runs Python bytecode at a time. Threads still help with I/O, because the GIL is released while a thread waits. But pure-Python number crunching gets no faster with more threads. Processes avoid this because each one has its own interpreter and its own GIL.

Free-threaded Python: Python 3.13 added an experimental build with no GIL (python3.13t), and in 3.14 that build is officially supported. It's still a separate, optional build, and the default python keeps the GIL. On a free-threaded build, threads can run Python code in parallel on many cores.

Pip tip: In the browser (where PyQuest runs), threads and processes can't start. Try concurrent.futures on your own computer!

On standard CPython, you must run a heavy pure-Python calculation on 8 big datasets and use all 8 CPU cores. What's the best fit?