Lets Talk About GIL
AMiT Kumar (~aktech) |
I will be talking about Global-Interpreter-Lock (GIL)  in Python. It's a mutex that prevents multiple native threads from running in parallel. In essence, this says that a python program cannot do more than one thing at once via threading .
There is lot of misconception in majority of Python Programmers regarding Global Interpreter Lock. Most of them think its the worst part of Python. I will try to demonstrate how it actually works and how we can leverage multiple CPU cores for multithreading for I/O and CPU Bound tasks. I will also show some comparisons with different implementations of Python and the presence or absence of GIL in those, to answer questions like, why we can't just remove it from CPython and solve all our problems or why Jython performs better in Multithreading for CPU Bound task.
- Whats a Process?
- Whats a Thread?
- Why Multithreading?
- Multithreading in Python
- Threading Module in Python (Thread Class, functions as thread)
- Why Sequential execution is Faster than multithreaded one? (In an Example)
- Global Interpreter Lock
- I/O Bound and CPU Bound Processes
- GIL Behaiviour on these two types of Process
- Guido On GIL
- The Famous GIL Removal Patch
- Multithreading in Other Python Implementations
- What's next?
Amit is a Software Development Engineer at Zomato's Machine Learning Team. He is also a core developer of SymPy Library. He is a programmer, learner, presenter and a Software Engineer in the process. He has spoken at various national and international conferences and local meetups. You may find him with handle @aktech on the Web.