DEV Community

Discussion on: Explain python global interpreter lock (GIL) Like I'm Five

 
idanarye profile image
Idan Arye

GIL is also a three letter acronym - I don't see you explaining about acronyms.

Thread Thread
 
msoedov profile image
Alex Miasoiedov

What difference does it make? The simplest as possible explanation for 5 years does not supposed to rely on definition of mutex, semaphore, object graph traversal, several generation of garbage collection objects, entire posix standard, linux kernel internals, architecture of cpu's, modern microelectronics and recent discoveries of quantum field theory.

Thread Thread
 
idanarye profile image
Idan Arye

Of course not - that's going down into details, when you should go up.

Say you go to take your bike from where you left it, and you see me putting my own chain and lock on it. You approach me - "mind explaining this lock?" - and I start explaining what locks are used for and why humans need to lock things. But that's not what you wanted, right? You probably didn't want an explanation on the internal clockwork of the lock either. No - what you wanted me to explain is why I put a lock on your bike.

When someone asks a about a specific lock, they want to know why you need a lock there. The GIL is a "hidden" lock - it's applied automatically by the Python interpreter and you don't usually notice it - so asking for it to be explain is asking what it locks and why it needs to be locked - not what's the purpose of locks in general.

Thread Thread
 
msoedov profile image
Alex Miasoiedov • Edited

Idan, I understand where you coming from. Oversimplified explanation might zoom out from all of this concrete details. Nevertheless it at least can explain thing for those who don't know what mutex is.

The GIL is a "hidden" lock it's applied automatically

The word hidden and applied automatically are kind of misleading. GIL is implementation detail of Cpython's reference counting garbage collector and it could be implemented without it.

Thread Thread
 
rachit_gupta_ profile image
Rachit Gupta • Edited

Hi Alex, i got some questions regarding this ?
1) it was fine when we were considering the Python only, the basic python3 which ships with linux, and i understand that GIL is applicable to multi-processing but not to multi-threading ? please correct me if i'm wrong ?

2) How do CPython comes into play with the standard Python and how differently GIL plays it's role in Python and as well as it's other implementations ?

3) Although, libraries like numpy and pandas are written in C, so do GIL will play it's role here as well ? so can we take advantage of multi-processing by default ( that is not implementing multi-processing module explicitly ) ?

Can you help me with this ?