Nice post sir! However I want to know why we need interpreter level lock on threads?
Ankit Singh
1

The GIL prevents simultaneous access to Python objects by multiple threads. It has several advantages. It is this GIL only which keeps garbage collection in Python working which is the reason why we usually dont have to worry about memory management in Python. Although garbage collection deserves another writeup, still you need to know it works by reference count here. GIL is only preventing one thread from altering this count while another thread is acting on it. GIL is made with objective of simpler interpreter implementation. It makes maintenance of interpreter also easier since there is no need to worry about memory management and concurrency issues which might be problematic. To quote “In 1999 Greg Stein had created a patch set for the interpreter that removed the GIL, but added granular locking around sensitive interpreter operations. This patch set had the direct effect of speeding up threaded execution, but made single threaded execution two times slower.” So with GIL you get awesome speed too.

Like what you read? Give PAWAN PUNDIR a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.