Is Your Python Code Unsafe? GIL’s Hidden Secret

preview_player
Показать описание
In this video, we take a deep dive into the inner mechanics of Python's Global Interpreter Lock (GIL), which is a must for all threading and multiprocessing devs, and expose a subtle nuance, which could potentially make your code unsafe. Join us as we explore the impact of GIL on threading and multiprocessing, and discover how it affects the performance and scalability of your Python programs. By the end of this video, you'll gain valuable insights and learn proper threading practices that can help you avoid potential pitfalls.

0:00 - Overview
1:15 - Python threading example
3:50 - Threading
5:46 - GIL (Global Interpreter Lock)
6:24 - CPU bound vs IO bound
7:40 - Purpose of GIL
8:21 - Multiprocessing
9:25 - GILs downfall

MUSIC CREDITS:
LEMMiNO - Cipher
CC BY-SA 4.0

LEMMiNO - Nocturnal
CC BY-SA 4.0
Рекомендации по теме
Комментарии
Автор

Answer for your crimes: Why have you created an anime OC for the GIL?

TheArtikae
Автор

Never know stuff that I thought unrelevant in my Operating System course could have so much potential impact on coding lol

naumbtothepaine
Автор

The GIL protects pythons internal interpreter state, that does not mean that you cannot introduce race conditions of your own as in this example. The job of the GIL is not to ensure that data structures that you choose to use are atomically locked

VeryaliveWoW
Автор

the 5ms constant is all you need to add some wildly difficult heisenbugs to your code.

kolaysgames
Автор

1:47 what you did here was so amazing 😭 He just made everything a for loop function in .5 🎉

TheControlMastr
Автор

great video i mean first mistake trying to use multi threading in python if you need speed just use go lmao.

dracula
Автор

High quality vid, thanks a lot for this!

oxi
Автор

Love your videos. Hope to see you with a mil+ subscribers one day 🙏🏾

tiwongemhango
Автор

Great video, but where did you get the Python waifu image from?

CielMC
Автор

If Gil ends up doing nothing and the only thing that prevents race conditions is the operating system, why Gil even exist? Let's let all the task to the os and the code can run 4x faster.

ivanleonelvera
Автор

great video.
i clicked because of the waifu, but still didnt figure out why she is there lol

igorgiuseppe
Автор

I am studying this at operating system subject of my career and its very interesting. A single process can have multiple threads and the data can be accesed between threads and thats why without GIL your code can have different results. Multithreading itself is a threat to security due the way it works (if not handled properly). Thats why web browser can't be multithreaded, because that could mean a tab runing one page could acces information on another tab. Thats why browsers use multiproccesing instead, F.E. Firefox creates one proccess per tab (and that is also why JavaScript is singleThread only, not because they are lazy to implement multithreading but because its more secure).
Processes are managed by the OS, they can also share information and they are organized in a hierarchy tree (father processes could have sons and so on)
But I'm not sure if the OS give each procces its own thread or they are executed in other way.

ionrael
Автор

Can I use AI to make a 24 hour version of this video but replace everything you're saying with some gibberish because its so soothing but packed with crazy good info at the same time.
I want this to run in the bg while I work but not get tired of absorbing info / info saturated.
Even the bg music choice was so good.
Don't appreciate the clickbait tho :/

Proprogrammer
Автор

Your voice is too low compared to the background music volume. Sometimes it's hard to understand what are you talking.

bitpilot
Автор

What did you use to create that blue haired character tho at 0:18?

aurkom
Автор

got an ad literally every minute(note this is more than the default rate by about 3 to 4 times) hence Im not watching this despite how interesting it is

HHHjb_
Автор

Nice video, tho that multiprocessing code is the textbook example of what not to do when you use multiprocessing. I also find your pronunciation of GIL horrific :(

Zsombro
Автор

"In fact, it is a mathematical certainty that my CPU will never perform more than 4 operations at once."
That's true, but only if you ignore instruction-level parallelism and SIMD.

cancername