Posts

Showing posts with the label Python GIL

Python advanced #001 GIL (2020)

Image
  1. What is GIL? The GIL (global interpreter lock) is used by CPython interpreter which written in C programming language. There are other python interpreters that are written in other languages, such as JPython written in Java. CPython uses this GIL lock to make sure that only one thread executes python bytecode at a time. The other thread must wait for its release. Using this GIL, CPython ensures that when a thread is executing python bytecode, any python objects will not be accessed by another thread. It provides a safe threading way to achieve multitasking. Its downside is more obvious in modern computers which always feature multi-core cpus. Because only one thread could execute code at a time, CPython will only occupy one cpu core at a time leaving other cpu cores idle.  1.1 Why Guido doesn't remove it Actually, Guido (creator of Python) did that several years ago. But eventually, he quit and make a statement that removing the GIL is not an easy task; by removing GIL could s