What is the Global Interpreter Lock?
The Global Interpreter Lock (GIL) is used to protect Python objects from being modified from multiple threads at once. Only the thread that has the lock may safely access objects.
To keep multiple threads running, the interpreter automatically releases and reacquires the lock at regular intervals (controlled by the sys.setcheckinterval function). It also does this around potentially slow or blocking low-level operations, such as file and network I/O.