What is the GIL (Global Interpreter Lock) in Python?
Why Interviewers Ask This
This tests whether you can apply Python knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.
Answer
The GIL (Global Interpreter Lock) is a mutex in CPython (the reference Python implementation) that ensures only one thread executes Python bytecode at a time, even on multi-core systems. This simplifies memory management (CPython uses reference counting) but limits true parallel execution of Python code across multiple CPU cores. CPU-bound tasks (heavy computation) do NOT benefit from Python threads due to the GIL. I/O-bound tasks (network requests, disk I/O) DO benefit from threads — the GIL is released during I/O operations. For CPU parallelism, use multiprocessing (separate processes, no GIL) or concurrent.futures.ProcessPoolExecutor. For I/O parallelism, use threading, asyncio, or concurrent.futures.ThreadPoolExecutor. Alternative Python implementations (Jython, PyPy-STM) do not have a GIL.
Common Mistake
A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.