In standard CPython, the Global Interpreter Lock (GIL) allows only one thread to execute Python bytecode at a time. So threads do not speed up CPU-heavy pure-Python code.
What this means in practice:
I/O-bound work (web requests, file and database access): threads and asyncio still help a lot, because a thread releases the GIL while it waits.
CPU-bound work (heavy calculations): use multiprocessing or concurrent.futures.ProcessPoolExecutor, which uses separate processes with separate GILs. Or use libraries such as NumPy, whose heavy loops run in C and can release the GIL.
Newer Python versions are working on a free-threaded build, but it is optional and still developing, so check the current docs before relying on it.
So do not avoid threading blindly. Decide first whether your task waits on I/O or burns CPU.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
In standard CPython, the Global Interpreter Lock (GIL) allows only one thread to execute Python bytecode at a time. So threads do not speed up CPU-heavy pure-Python code.
What this means in practice:
concurrent.futures.ProcessPoolExecutor, which uses separate processes with separate GILs. Or use libraries such as NumPy, whose heavy loops run in C and can release the GIL.So do not avoid threading blindly. Decide first whether your task waits on I/O or burns CPU.