What is the GIL in Python?

The GIL (Global Interpreter Lock) is a lock inside CPython, the standard Python, that allows only one thread to run Python bytecode at a time. It keeps memory management simple and safe.

Because of the GIL, several threads doing heavy calculation do not run in parallel on different CPU cores. But it is released while a thread waits for files, network or database, so threads still work well for such waiting tasks.

Task typeBetter choice
Waiting for network, files, database (I/O bound)threading or asyncio
Heavy calculation (CPU bound)multiprocessing, where each process has its own interpreter and GIL

Python 3.13 also added an experimental build that can run without the GIL, but the normal build still has it. Other implementations such as Jython do not have a GIL.


Learn more about the similar topics:
Tutorials
Python Decorators
Python Closures
Python Iterators and Generators
Python Modules
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is a decorator in Python?
What are iterators in Python?
What is a generator in Python?
What is the GIL in Python?
What is the difference between a module and a package in Python?
How does Python manage memory?
What is the with statement in Python?