⚙️Global Interpreter Lock (GIL)
Also known as GIL, Python GIL
A lock in Python that lets one thread run Python code at a time.
Think of it like
Think of it like a talking stick. Only the one holding it may speak.
Example
Emma runs a maths job in 4 threads on a 4-core laptop. It takes as long as 1 thread, because of the GIL. With 4 processes, each with its own GIL, it ends far sooner.
Definition
Example code
python
>>> import sys
>>> sys._is_gil_enabled()
TrueCommon mistake
Key takeaways
- 1One thread at a time. For running Python code.
- 2Let go while waiting. Files and network still overlap.
- 3Optional since 3.13. A build with no GIL exists.