Python Developer interview question
What is the Python GIL?
The GIL is a CPython mutex that lets only one thread execute Python bytecode at a time; threads still help I/O, while CPU-bound parallelism usually needs processes or native code that releases it.
Direct answer
What a strong answer covers
How it works
CPython protects its interpreter state and reference counts with one global lock, so two threads never run Python bytecode simultaneously in the same process. The lock is released during blocking system calls and inside many C extensions such as NumPy, which is why threads still speed up network or file work. For CPU-bound Python code, parallelism comes from multiprocessing, a task queue with separate workers, or native code; recent CPython builds offer an experimental free-threaded mode, but most deployments still run with the GIL.
Example
A web scraper with 50 threads finishes far faster than a single thread because each thread waits on sockets while others run. The same 50 threads computing hashes in pure Python finish no faster than one, so the hashing moves to a ProcessPoolExecutor and the wall time drops roughly with the core count.
Common mistakes
- Claiming threads are useless in Python and ignoring the I/O case.
- Believing the GIL makes Python code thread-safe, when compound operations still race.
- Choosing multiprocessing for I/O work and paying for process startup and pickling for nothing.
A useful answer structure
Answer from your own work.
Do not memorise a script: use only examples you can explain honestly in follow-up questions.
Open the desktop workspace and rehearse a clear answer in your own words.