From the course: Complete Guide to Parallel and Concurrent Programming in Python

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Global interpreter lock: Python demo

Global interpreter lock: Python demo

- [Instructor] Using threads to handle concurrent tasks in Python is fairly straightforward. However, the Python interpreter will not allow those concurrent threads to execute simultaneously in parallel due to a mechanism called the Global Interpreter Lock or GIL. It's something that's unique to Python and important to address upfront. The GIL is a mechanism in Python that prevents multiple Python threads from executing at the same time. That means if your program is written to have 10 concurrent threads, only one of them can execute at a time, while the other nine wait their turn. This may seem like an odd limitation, but remember that, under the hood, your Python program is actually being executed by a program called an interpreter. The interpreter compiles your Python program into an intermediate byte code, which is then executed with a virtual machine along with any necessary modules from the library. The default and by far most widely used interpreter is CPython, and as its name…

Contents