Chapter 15
- C++ associates a variable with its value by simply writing the value to the memory location of the variable; Python has its variables reference point to the memory location of the values that they hold. For this reason, Python needs to maintain a reference count for every value in its memory space.
- To avoid race conditions and, consequently, value reference counts from being corrupted, the GIL is implemented so that only one thread can access and mutate the counts at any given time.
- The GIL effectively prevents multiple threads from taking advantage of the CPU and executing CPU-bound instructions at the same time. This means that if multiple threads that are meant to be executed concurrently are CPU-bound, they will be executed sequentially.
- There are a few ways to deal with the GIL in your Python applications; namely, implementing multiprocessing instead of multithreading and utilizing other, alternative Python interpreters.