DEV Community

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

Collapse
 
rhymes profile image
rhymes • Edited

Your parents buy ONE toy for your and your sibling.

They tell you can both play with it in the toy room and only one of you can enter at a time. To make sure you respect the instructions you have to go ask them each time who can play it first.

the toy is the variable, the room is the GIL, the parents are the interpreter, you and your sibling are the threads

Hope it makes sense :D

Collapse
 
docoprusta profile image
Soma Györe

Great thanks. If I understand it correctly the GIL is kind of an automatic mutex implementation. Is it correct?

Collapse
 
rhymes profile image
rhymes

Exactly, it's a giant mutex that serialises access to non thread safe resources.

Thread Thread
 
idanarye profile image
Idan Arye

And in Python - everything except IO is considered non-thread-safe.