The GIL and its effects on Python multithreading
As you probably know, the GIL stands for the Global Interpreter Lock, and its job is to make the CPython interpreter thread-safe. The GIL allows only one OS thread to execute Python bytecode at any given time, and the consequence of this is that it's not possible to speed up CPU-intensive Python code by distributing the work among multiple threads. This is, however, not the only negative effect of the GIL. The GIL introduces overhead that makes multi-threaded programs slower, and what is more surprising, it can even have an impact on I/O-bound threads. In this post I'd like to tell you more about non-obvious effects of the GIL. Along the way, we'll discuss what the GIL really is, why it exists, how it works, and how it's going to affect Python concurrency in the future. Note: In this post I'm referring to CPython 3.9. Some implementation details will certainly change as CPython evolves. I'll try to keep track of important changes and add update notes. Let me first remind you what Pytho
As you probably know, the GIL stands for the Global Interpreter Lock, and its job is to make the CPython interpreter thread-safe. The GIL allows only one OS thread to execute Python bytecode at any given time, and the consequence of this is that it's not possible to speed up CPU-intensive Python code by distributing the work among multiple threads. This is, however, not the only negative effect of the GIL. The GIL introduces overhead that makes multi-threaded programs slower, and what is more surprising, it can even have an impact on I/O-bound threads. In this post I'd like to tell you more ab
Explore this link on the map →related reading
- What Is the Python Global Interpreter Lock (GIL)? – Real Pythonrealpython.com
- PEP 703 – Making the Global Interpreter Lock Optional in CPython | peps.python.orgpeps.python.org
- Global interpreter lock - Wikipediaen.wikipedia.org
- Multithreading and Multiprocessing in 10 Minutes | Towards Data Sciencetowardsdatascience.com
- Multithreading (computer architecture) - Wikipediaen.wikipedia.org
- An Intro to Threading in Python – Real Pythonrealpython.com
- Notes on structured concurrency, or: Go statement considered harmful - njs blogvorpus.org
- Multi Core Programming and Threadsimomath.com
- Running Python Parallel Applications with Sub Interpreterstonybaloney.github.io
- To Thread or Not to Thread: An In-Depth Look at Ruby’s Execution Models - Shopifyshopify.engineering
- BrrrVizbrrrviz.com
- Using Threads to Run Code Simultaneously - The Rust Programming Languagedoc.rust-lang.org