THN Interview Prep

Python — GIL, async & when not to use it

Python GIL and async boundary diagram showing CPython thread contention, I/O waits releasing the GIL, asyncio for I/O-bound services, thread-pool offload, and process-based CPU parallelism.

Core details

CPython executes bytecode with a Global Interpreter Lock: one thread runs Python bytecode at a time per process.

WorkloadTypical approach
I/O-boundasyncio or threads often fine; many waits release GIL
CPU-boundmultiprocessing, native extensions, or other language—threads won’t parallelize CPU-heavy Python

async/await: cooperative multitasking; blocking calls in async def (sync DB client) stalls the loop—use async drivers or thread pool offload.

Understanding

GIL is CPython-specific; other implementations differ. Interview honesty: “For heavy numeric work I’d reach for vectorized libs or process pool.”

Senior understanding

Django / Flask sync vs ASGI stack; deployment (gunicorn workers vs uvicorn). Memory: generational GC; reference cycles need weakref awareness in extensions.

See also

Mark this page when you finish learning it.

Last updated on

Spotted something unclear or wrong on this page?

On this page