Global Interpreter Lock
The Global Interpreter lock of python allows only one thread to be executed at a time , python does not support multithreading. It is not possible to use multiple processors with threads in Python though there are libraries available to achieve it.
What problem does Global interpreter lock solve , Basically to understand that we need to know how python handles memory management. Memory management in python is done using reference counting , Reference counting is nothing but every object we create will have a reference count object will maintain the number of references the object has. The problem was that this reference count variable needed protection from race conditions where two threads increase or decrease its value simultaneously which in turn will cause bugs in the program.
import sys
a = []
print(sys.getrefcount(a))
Output : 2
# 2 references, 1 from the 'a' var and 1 from getrefcount
Contributed By::
Shilpa Sreekumar
Technology Lead