Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
The Global Interpreter Lock lets only one thread execute Python bytecode at a time, so threads do not speed up CPU-bound Python code, but they still help I/O-bound work because the GIL is released while waiting on I/O.
CPython uses the GIL to protect its internal state, such as reference counts, without fine-grained locks. As a result, two threads running pure Python calculations take turns rather than running in parallel on two cores. Blocking I/O calls and many C extensions, such as NumPy operations, release the GIL, so threads work well for network calls, disk access or waiting on databases. For CPU-bound work you use multiprocessing, native extensions, or the optional free-threaded builds available since Python 3.13. The GIL does not make your code thread-safe: operations like counter += 1 can still be interrupted between steps.