Global Interpreter Lock (GIL)

It is a implementation in CPython which puts a lock on the interpreter in multithreading. Only a single thread can access the interpreter at a time.

In IO bound multithreading, threads wait for IO and meanwhile another thread can access the interpreter.

In the case of CPU bound multithreading, one thread doesn’t leave the interpreter and executes behaves as single threaded as other threads have to wait for the interpreter to get released.

Pros

  1. Makes single threading faster as there is only lock, that is GIL lock, to maintain.
  2. Good for IO bound multithreading programs.

Cons

  1. Not good for CPU bound and combinations of both IO and CPU bound multithreading programs.

References

  1. https://realpython.com/python-gil/#what-problem-did-the-gil-solve-for-python