The Python Global Interpreter Lock - Explained
Skills:
Systems Design Basics60%
Key Takeaways
The video explains the concept of the Global Interpreter Lock (GIL) in Python, its impact on parallel processing, and how it can be sidestepped using multi-processing.
Full Transcript
let's talk about one of the most controversial features in Python the G or Global interpreter lock in essence this feature disallows parallel processing and restricts your program such that it can only run one thread at a time to better understand this let's have a look at how traditional programs are executed by your CPU in 2023 a typical CPU has four cores and between four to eight threads to keep our example simple we'll imagine that each core only has one Hardware thread each CPU core is a physical processing unit that is capable of handling one task at a time the more cores we have the more tasks we can process at the same exact time the types of tasks that CPU cores handle are called software threads it can get confusing but software threads are created by applications while Hardware threads exist on the physical CPU from now on we'll only be referring to software threads now software threads are portions of applications or programs that can be run independently by a CPU core the more cores we have the more threads we can execute at the same time this means that we can speed up our programs by splitting them into multiple threads so let's take an example where we want to sum the numbers from 1 to 20 well if we do this with a single thread we're only utilizing one of our four CPU cores to speed up this operation we can split our program into four threads where each thread is responsible for summing a portion of the numbers thread 1 can sum the numbers 1 to 5 thread 2 sums 6 to 10 thread 3 three sums 11 to 15 and thread four sums 16 to 20 now that we're using four threads we can use four CPU cores and we sped up our program by four times now this adds a bit of complexity but overall it's worth the trade-off now here comes the bad news in Python it doesn't quite work this way whenever we execute code we use something called an interpreter to keep it simple this is what's capable of understanding the code and processing the instructions that we wrote that means that in the previous example each one of our threads will need to access a code interpreter whenever it's executing instructions in most languages this is fine multiple threads can use the same interpreter at the exact same time but in Python we have something called a lock now a lock is essentially a gate that only lets one thread through at a time since we have a lock on our python interpreter that means that even though we have four threads only one can use The Interpreter at a time if a thread is using The Interpreter it can release the lock allowing another thread to access it but only one thread can be using The Interpreter at the same time that in essence is the python Global interpreter lock now at this point you might be asking yourself why would I ever use multiple threads in Python well the answer is when you're working with network or input output type operations now imagine a simple example where a user visits your app the app may need to load the user's friends and chat history from a file or from some API now while this loading is happening you still want your user to be able to interact with the app if you were to play place all of this logic in one single thread the app would freeze waiting on the data to be loaded before the user can do anything else on the app or before you can load additional data now if you split this operation into three threads even though only one thread can execute at a time you can execute a different thread while one thread is waiting on a result from the file system or the server or network so what we'll do here is we'll make a thread to load the chat history a thread to load the friends and a thread that runs the user interface we start by running the chat history thread which quickly sends a request to a server for some results This Thread then hangs waiting on a result now as soon as it starts waiting we can switch to execute a different thread in this case the friend's thread same here as soon as it starts waiting we execute the user interface thread allowing the app to run while the data is loading now once we receive the data we can quickly switch back to the other threads process that data and move on this allows us to execute data concurrently so the CPU can always be working and never waiting on a result that we don't have control over creating multiple threads allows us to switch between those different threads so we're always utilizing the CPU so now that we have a good understanding of threading let's briefly discuss multi-processing python has a multiprocessing module which allows us to create separate processes now as a simplification you can imagine that each process spawns its own instance of the Python interpreter this means that we can sidestep the global interpreter lock and run a truly parallel application now multi-processing is not as easy to handle as multi-threading but this is a solid solution to avoid the global interpreter lock so now at this point you know about one of the most controversial features in Python the global interpreter lock if you want to learn more about python make sure to subscribe to this channel I look forward to seeing you in another one [Music]
Original Description
To learn programming and Python - check out Datacamp!
💻 Learn Python - https://datacamp.pxf.io/4PODjr
💻 Learn Programming - https://datacamp.pxf.io/3e6xrk
Today, I'm revealing the worst feature Python has... The GIL (Global Interpreter Lock)! We'll be going over what the GIL is, how it compares to traditional programs, and why it's one of the worst features.
🎬 Timestamps⏱️
00:00 | What is The GIL
00:18 | How Traditional Programs Work
01:44 | The Problem With Python
02:37 | Why Use Multiple Threads in Python
04:10 | Multi-Processing
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
👕 Merchandise: 🔗 https://teespring.com/stores/tech-with-tim-merch-shop
📸 Instagram: 🔗 https://www.instagram.com/tech_with_tim
📱 Twitter: 🔗 https://twitter.com/TechWithTimm
🔊 Discord: 🔗 https://discord.gg/twt
📝 LinkedIn: 🔗 https://www.linkedin.com/in/tim-ruscica-82631b179/
🌎 Website: 🔗 https://techwithtim.net
📂 GitHub: 🔗 https://github.com/techwithtim
One-Time Donations: 💲 https://www.paypal.com/donate?hosted_button_id=CU9FV329ADNT8
Patreon: 💲 https://www.patreon.com/techwithtim
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
⭐️ Tags ⭐️
- Tech With Tim
- The GIL
- Python
⭐️ Hashtags ⭐️
#programming #python #coding
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Tech With Tim · Tech With Tim · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
A* Path Finding Algorithm(Visualization)
Tech With Tim
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
Python Programming Tutorial #3 - Conditions
Tech With Tim
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
Python Programming Tutorial #6 - For Loops
Tech With Tim
Python Programming Tutorial #7 - While Loops
Tech With Tim
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
Python Programming Tutorial #10 - String Methods
Tech With Tim
How to Overclock a NVIDIA GPU
Tech With Tim
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
Python Programming Tutorial #12 - Functions
Tech With Tim
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
Cool VBS Script to Prank Your Friends!
Tech With Tim
How to Overclock an AMD GPU
Tech With Tim
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
Recursion and Memoization Tutorial Python
Tech With Tim
Ethereum Mining Rig - Hardware Guide
Tech With Tim
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
How to Install Pygame (Windows 8/10)
Tech With Tim
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
Linear Search Algorithm - Python Example and Code
Tech With Tim
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
Binary Search Algorithm - Python Example & Code
Tech With Tim
Pygame Tutorial #5 - Projectiles
Tech With Tim
Pygame Game - Mini Golf
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
Pygame Tutorial #6 - Enemies
Tech With Tim
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
How to Create A Message Box in Python - Tkinter
Tech With Tim
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim
More on: Systems Design Basics
View skill →Related Reads
📰
📰
📰
📰
On July 1, 2026, arXiv will spin out from Cornell University, its home for the past 25 years, to become an independent nonprofit organization. Major funding support from Simons Foundation and Schmidt Sciences. Ditching the red for their website. [N]
Reddit r/MachineLearning
CS-NRRM™ Official Publications: Paper 1 and Paper 2 Are Now Available
Medium · Data Science
Found a potential mistake in an ICLR 2026 blogpost [D]
Reddit r/MachineLearning
Rebuttals Move Peer-Review Scores, but Initial-Review Structure Bounds the Movement
ArXiv cs.AI
Chapters (5)
| What is The GIL
0:18
| How Traditional Programs Work
1:44
| The Problem With Python
2:37
| Why Use Multiple Threads in Python
4:10
| Multi-Processing
🎓
Tutor Explanation
DeepCamp AI