ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.1 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://jerrynsh.com/python-gil-explained-like-im-five/ |
| Last Crawled | 2026-04-03 11:18:28 (3 days ago) |
| First Indexed | 2023-02-01 01:12:34 (3 years ago) |
| HTTP Status Code | 200 |
| Meta Title | GIL in Python: Explained Like I'm Five |
| Meta Description | ELI5 about what Python GIL is. Learn how GIL affects CPython and bytecode execution, and get a TL;DR of the ongoing debate surrounding the GIL. |
| Meta Canonical | null |
| Boilerpipe Text | So, you have heard of the
Global Interpreter Lock
, or GIL for short? What exactly is GIL? Well, in short GIL is a mechanism that is built into the CPython interpreter. It is designed to prevent multiple native threads from executing Python bytecodes at once.
“Blah-blah-blah, stop trying to sound smart! What the hell are CPython and bytecode?!”. Hopefully, I haven’t lost you yet at this point.
Before we start talking about GIL, let me briefly introduce to you what CPython and bytecode are to understand the
typical
answers about GIL that you read on the Internet.
Don’t worry, it’s not as scary as it sounds! Here's my GIL
ELI5
take.
What is CPython
Just like how there are many different brands of soda (Coke, Pepsi, Mountain Dew, etc.), there are also many different versions of Python that you can use to write and run your programs.
CPython
is like the "original" or "standard" version of the Python programming language. You’re probably using it every day!
Reference implementation
Written in C, CPython is called the "
reference implementation
" of Python, which means that it's the version that other versions of Python are compared to and tested against.
It's a bit like how Coke is the original soda that other sodas are based on or try to imitate.
Not actually compiling to C
To be clear, CPython does
not
translate your Python code to C. The
Cython project
on the other hand lets you compile your code to C.
Alternatives
Several alternative implementations of Python are built to address different needs or to improve the performance of CPython in certain areas.
A non-exhaustive list of alternative implementations of Python includes:
PyPy
: a fast, compliant implementation of Python that is built using a just-in-time compiler. It is often faster than CPython, particularly for larger programs.
Jython
: an implementation of Python that is written in Java and can be used to run Python code on the Java Virtual Machine (JVM). This allows Python programs to integrate with Java programs and libraries.
IronPython
: an implementation of Python built using the .NET framework and designed to be used with other .NET languages such as C#.
What is bytecode
Are you ready to learn about the mysterious world of Python bytecodes? Buckle up!
When you write a Python program and run it, the Python interpreter first compiles the source code into bytecodes and then executes the bytecodes to produce the desired output.
Soda analogy
Imagine that you have a recipe for making the perfect soda. The recipe is written in a language that you can understand, like English.
But when you go to make the soda, you don't actually follow the recipe in English. You translate it into a series of instructions that your soda machine can understand – these instructions are the "bytecodes".
Came across
.pyc
?
In Python, bytecodes are a lower-level representation of the source code of a Python program.
They are typically stored in files with an
.pyc
extension, which stands for "Python compiled code". These files are created automatically by the Python interpreter when it encounters a
.py
file that it needs to execute.
They are used to speed up the execution of Python programs by avoiding the need to recompile the source code each time the program is run.
So that's bytecode in a nutshell! It's a set of instructions that tells your computer what to do, kind of like a recipe for soda.
Just don't try to drink your bytecode — that would be a bit weird.
Why is GIL necessary
Well, you see, CPython wasn’t designed to be thread-safe. In other words, multiple threads can potentially interfere with one another. This is bad because it can lead to something called “
race condition
”.
The GIL makes our life easier as Python developers to write multi-threaded programs without worrying about race conditions.
How do I use GIL?
In case you’re wondering — you
don't
need to do anything special to use the GIL in your Python code. It is implemented automatically in the CPython interpreter and is active by default.
However, you can use the
threading
module (
docs
) to create and manage threads in your Python code:
import threading
def make_soda():
print("Making a delicious soda!")
if __name__ == "__main__":
t1 = threading.Thread(target=make_soda)
t2 = threading.Thread(target=make_soda)
t3 = threading.Thread(target=make_soda)
t1.start()
t2.start()
t3.start()
Race condition
Imagine that you and your friends are making a batch of soda together. You've got all the ingredients ready to go — sugar, water, caramel coloring, and some secret spices.
But you all try to add the ingredients to the same pot at the same time. This can lead to unexpected results because you don't know which ingredients will be mixed in first. This is similar to a race condition in a program, where two or more threads try to modify the same shared resource at the same time!
But because the GIL is in place, the other thread will have to wait for its turn before it can start making some fizzy goodness.
You may have already noticed — GIL may seem like a bottleneck because of this wait. But, it’s actually just there to keep things running smoothly.
Input/Output (I/O) Bound
It is important to note that GIL does
not
affect programs that rely on I/O operations as these operations typically release the GIL while waiting for data to be transferred.
What exactly do you mean by I/O bound?
At its most basic, I/O bound means that a program is waiting for I/O operations to complete. This can include things like:
Reading from or writing to a file
Sending or receiving data over a network
Interacting with a user through a graphical user interface (GUI), etc.
Essentially, any time a program has to wait for something to happen outside of itself, it's probably doing I/O-bound work.
The Debate
A TL;DR about all the fuss about the Global Interpreter Lock, or GIL.
Supporters
“The GIL is a great feature of Python! It makes it easy for us to write multi-threaded programs without having to worry about race conditions!” – says the supporters.
They argue that
most
Python programs aren’t CPU-intensive, to begin with. Most of the time, the programs are doing I/O-bound work which GIL doesn’t really affect. So, why all the fuss?
Critics
“The GIL is holding us back!” – say the critics with an opposite view.
With GIL, only one thread can execute Python bytecodes at a time.
As a result, this can limit the performance of CPU-bound Python programs on systems with multiple CPU cores. Because of this, GIL is known as a major limitation of Python.
Although most Python programs are I/O-bound, it doesn’t mean that we shouldn’t be able to write high-performance CPU-bound programs in Python.
Conclusion
So who's right? Well, as with most debates, there's no easy answer.
The GIL may be a necessary compromise that makes it easy for Python programmers to write multi-threaded programs. Nevertheless, it can also limit the performance of CPU-bound programs on systems with multiple CPU cores.
The debate lives on, for now, I guess. Lastly, check out
this HN post and comments
if you're interested to dive a little bit deeper into the wonderful world of GIL. |
| Markdown | [](https://jerrynsh.com/)
- [🔵 About](https://jerrynsh.com/about/)
- [đź’¬ Contact](https://jerrynsh.com/contact/)
- [đź’ Food for Thought](https://jerrynsh.com/food-for-thought/)
[Sign in](https://jerrynsh.com/python-gil-explained-like-im-five/#/portal/signin) [Subscribe](https://jerrynsh.com/python-gil-explained-like-im-five/#/portal/signup)
[Python](https://jerrynsh.com/tag/python/)
# GIL in Python: Explained Like I'm Five
- [](https://jerrynsh.com/author/jerrynsh/)
#### [Jerry Ng](https://jerrynsh.com/author/jerrynsh/)
Feb 1, 2023
• 5 min read
So, you have heard of the [Global Interpreter Lock](https://wiki.python.org/moin/GlobalInterpreterLock), or GIL for short? What exactly is GIL? Well, in short GIL is a mechanism that is built into the CPython interpreter. It is designed to prevent multiple native threads from executing Python bytecodes at once.
“Blah-blah-blah, stop trying to sound smart! What the hell are CPython and bytecode?!”. Hopefully, I haven’t lost you yet at this point.
Before we start talking about GIL, let me briefly introduce to you what CPython and bytecode are to understand the *typical* answers about GIL that you read on the Internet.
Don’t worry, it’s not as scary as it sounds! Here's my GIL [ELI5](https://www.dictionary.com/e/slang/eli5/#:~:text=What%20does%20ELI5%20mean%3F,a%20complicated%20question%20or%20problem.) take.
## What is CPython
Just like how there are many different brands of soda (Coke, Pepsi, Mountain Dew, etc.), there are also many different versions of Python that you can use to write and run your programs.
[CPython](https://github.com/python/cpython) is like the "original" or "standard" version of the Python programming language. You’re probably using it every day\!
### Reference implementation
Written in C, CPython is called the "[reference implementation](https://wiki.python.org/moin/PythonImplementations)" of Python, which means that it's the version that other versions of Python are compared to and tested against.
It's a bit like how Coke is the original soda that other sodas are based on or try to imitate.
### Not actually compiling to C
To be clear, CPython does **not** translate your Python code to C. The [Cython project](https://cython.org/) on the other hand lets you compile your code to C.
### Alternatives
Several alternative implementations of Python are built to address different needs or to improve the performance of CPython in certain areas.
A non-exhaustive list of alternative implementations of Python includes:
1. [PyPy](https://www.pypy.org/): a fast, compliant implementation of Python that is built using a just-in-time compiler. It is often faster than CPython, particularly for larger programs.
2. [Jython](https://www.jython.org/): an implementation of Python that is written in Java and can be used to run Python code on the Java Virtual Machine (JVM). This allows Python programs to integrate with Java programs and libraries.
3. [IronPython](https://ironpython.net/): an implementation of Python built using the .NET framework and designed to be used with other .NET languages such as C\#.
## What is bytecode
Are you ready to learn about the mysterious world of Python bytecodes? Buckle up\!
When you write a Python program and run it, the Python interpreter first compiles the source code into bytecodes and then executes the bytecodes to produce the desired output.
### Soda analogy
Imagine that you have a recipe for making the perfect soda. The recipe is written in a language that you can understand, like English.
But when you go to make the soda, you don't actually follow the recipe in English. You translate it into a series of instructions that your soda machine can understand – these instructions are the "bytecodes".
### Came across `.pyc`?
In Python, bytecodes are a lower-level representation of the source code of a Python program.
They are typically stored in files with an `.pyc` extension, which stands for "Python compiled code". These files are created automatically by the Python interpreter when it encounters a `.py` file that it needs to execute.
They are used to speed up the execution of Python programs by avoiding the need to recompile the source code each time the program is run.
So that's bytecode in a nutshell! It's a set of instructions that tells your computer what to do, kind of like a recipe for soda.
Just don't try to drink your bytecode — that would be a bit weird.
## Why is GIL necessary
Well, you see, CPython wasn’t designed to be thread-safe. In other words, multiple threads can potentially interfere with one another. This is bad because it can lead to something called “[race condition](https://en.wikipedia.org/wiki/Race_condition)”.
The GIL makes our life easier as Python developers to write multi-threaded programs without worrying about race conditions.
### How do I use GIL?
In case you’re wondering — you **don't** need to do anything special to use the GIL in your Python code. It is implemented automatically in the CPython interpreter and is active by default.
However, you can use the `threading` module ([docs](https://docs.python.org/3/library/threading.html)) to create and manage threads in your Python code:
```
import threading
def make_soda():
print("Making a delicious soda!")
if __name__ == "__main__":
t1 = threading.Thread(target=make_soda)
t2 = threading.Thread(target=make_soda)
t3 = threading.Thread(target=make_soda)
t1.start()
t2.start()
t3.start()
```
### Race condition
Imagine that you and your friends are making a batch of soda together. You've got all the ingredients ready to go — sugar, water, caramel coloring, and some secret spices.
But you all try to add the ingredients to the same pot at the same time. This can lead to unexpected results because you don't know which ingredients will be mixed in first. This is similar to a race condition in a program, where two or more threads try to modify the same shared resource at the same time\!
But because the GIL is in place, the other thread will have to wait for its turn before it can start making some fizzy goodness.
You may have already noticed — GIL may seem like a bottleneck because of this wait. But, it’s actually just there to keep things running smoothly.
### Input/Output (I/O) Bound
It is important to note that GIL does **not** affect programs that rely on I/O operations as these operations typically release the GIL while waiting for data to be transferred.
What exactly do you mean by I/O bound?
At its most basic, I/O bound means that a program is waiting for I/O operations to complete. This can include things like:
1. Reading from or writing to a file
2. Sending or receiving data over a network
3. Interacting with a user through a graphical user interface (GUI), etc.
Essentially, any time a program has to wait for something to happen outside of itself, it's probably doing I/O-bound work.
## The Debate
A TL;DR about all the fuss about the Global Interpreter Lock, or GIL.
### Supporters
> “The GIL is a great feature of Python! It makes it easy for us to write multi-threaded programs without having to worry about race conditions!” – says the supporters.
They argue that *most* Python programs aren’t CPU-intensive, to begin with. Most of the time, the programs are doing I/O-bound work which GIL doesn’t really affect. So, why all the fuss?
### Critics
> “The GIL is holding us back!” – say the critics with an opposite view.
With GIL, only one thread can execute Python bytecodes at a time.
As a result, this can limit the performance of CPU-bound Python programs on systems with multiple CPU cores. Because of this, GIL is known as a major limitation of Python.
Although most Python programs are I/O-bound, it doesn’t mean that we shouldn’t be able to write high-performance CPU-bound programs in Python.
## Conclusion
So who's right? Well, as with most debates, there's no easy answer.
The GIL may be a necessary compromise that makes it easy for Python programmers to write multi-threaded programs. Nevertheless, it can also limit the performance of CPU-bound programs on systems with multiple CPU cores.
The debate lives on, for now, I guess. Lastly, check out [this HN post and comments](https://news.ycombinator.com/item?id=28690560) if you're interested to dive a little bit deeper into the wonderful world of GIL.
[](https://jerrynsh.com/building-what-michelin-wouldnt-its-awards-history/)
[Building What Michelin Wouldn’t: Its Awards History A few years back, I decided to gather Michelin restaurant data for fun. Over the years, something unexpected happened. My DMs and inbox started flooding with requests I kept having to turn down. Email after email asking the same thing: "Hey, I love your project! Do you have historical](https://jerrynsh.com/building-what-michelin-wouldnt-its-awards-history/)
Jul 17, 2025
8 min read
[](https://jerrynsh.com/how-to-replicate-duckduckgo-bangs-in-firefox/)
[How to Replicate DuckDuckGo Bangs in Firefox I finally made the switch from Chrome to Firefox (thanks to uBlock Origin drama). If you still get ads when watching YouTube with uBlock Origin, you might have read that recent news where uBlock Origin is now forcefully disabled by Chrome. While I still occasionally get force-fed with ads on](https://jerrynsh.com/how-to-replicate-duckduckgo-bangs-in-firefox/)
Jun 17, 2025
2 min read
[](https://jerrynsh.com/why-not-uppercase-in-go-modules-name/)
[Why Not Uppercase in Go Modules Name? I work with Go modules a lot at work. Over time, I've developed a habit of quickly checking the latest version of a module by visiting the /@latest endpoint of a Go proxy, like this: ❯ curl https://proxy.golang.org/github.com/aws/aws-sdk-go/@latest \| jq { "Version&](https://jerrynsh.com/why-not-uppercase-in-go-modules-name/)
Feb 18, 2025
3 min read
[Jerry Ng](https://jerrynsh.com/) © 2026
- [Now](https://jerrynsh.com/now/)
- [RSS](https://jerrynsh.com/rss/)
- [Privacy](https://jerrynsh.com/privacy-policy/)
- [Status](https://status.jerrynsh.com/)
[Powered by Ghost](https://ghost.org/)
Written by human. Hosted on [Digital Ocean](https://m.do.co/c/afdb6bd48884). |
| Readable Markdown | So, you have heard of the [Global Interpreter Lock](https://wiki.python.org/moin/GlobalInterpreterLock), or GIL for short? What exactly is GIL? Well, in short GIL is a mechanism that is built into the CPython interpreter. It is designed to prevent multiple native threads from executing Python bytecodes at once.
“Blah-blah-blah, stop trying to sound smart! What the hell are CPython and bytecode?!”. Hopefully, I haven’t lost you yet at this point.
Before we start talking about GIL, let me briefly introduce to you what CPython and bytecode are to understand the *typical* answers about GIL that you read on the Internet.
Don’t worry, it’s not as scary as it sounds! Here's my GIL [ELI5](https://www.dictionary.com/e/slang/eli5/#:~:text=What%20does%20ELI5%20mean%3F,a%20complicated%20question%20or%20problem.) take.
## What is CPython
Just like how there are many different brands of soda (Coke, Pepsi, Mountain Dew, etc.), there are also many different versions of Python that you can use to write and run your programs.
[CPython](https://github.com/python/cpython) is like the "original" or "standard" version of the Python programming language. You’re probably using it every day\!
### Reference implementation
Written in C, CPython is called the "[reference implementation](https://wiki.python.org/moin/PythonImplementations)" of Python, which means that it's the version that other versions of Python are compared to and tested against.
It's a bit like how Coke is the original soda that other sodas are based on or try to imitate.
### Not actually compiling to C
To be clear, CPython does **not** translate your Python code to C. The [Cython project](https://cython.org/) on the other hand lets you compile your code to C.
### Alternatives
Several alternative implementations of Python are built to address different needs or to improve the performance of CPython in certain areas.
A non-exhaustive list of alternative implementations of Python includes:
1. [PyPy](https://www.pypy.org/): a fast, compliant implementation of Python that is built using a just-in-time compiler. It is often faster than CPython, particularly for larger programs.
2. [Jython](https://www.jython.org/): an implementation of Python that is written in Java and can be used to run Python code on the Java Virtual Machine (JVM). This allows Python programs to integrate with Java programs and libraries.
3. [IronPython](https://ironpython.net/): an implementation of Python built using the .NET framework and designed to be used with other .NET languages such as C\#.
## What is bytecode
Are you ready to learn about the mysterious world of Python bytecodes? Buckle up\!
When you write a Python program and run it, the Python interpreter first compiles the source code into bytecodes and then executes the bytecodes to produce the desired output.
### Soda analogy
Imagine that you have a recipe for making the perfect soda. The recipe is written in a language that you can understand, like English.
But when you go to make the soda, you don't actually follow the recipe in English. You translate it into a series of instructions that your soda machine can understand – these instructions are the "bytecodes".
### Came across `.pyc`?
In Python, bytecodes are a lower-level representation of the source code of a Python program.
They are typically stored in files with an `.pyc` extension, which stands for "Python compiled code". These files are created automatically by the Python interpreter when it encounters a `.py` file that it needs to execute.
They are used to speed up the execution of Python programs by avoiding the need to recompile the source code each time the program is run.
So that's bytecode in a nutshell! It's a set of instructions that tells your computer what to do, kind of like a recipe for soda.
Just don't try to drink your bytecode — that would be a bit weird.
## Why is GIL necessary
Well, you see, CPython wasn’t designed to be thread-safe. In other words, multiple threads can potentially interfere with one another. This is bad because it can lead to something called “[race condition](https://en.wikipedia.org/wiki/Race_condition)”.
The GIL makes our life easier as Python developers to write multi-threaded programs without worrying about race conditions.
### How do I use GIL?
In case you’re wondering — you **don't** need to do anything special to use the GIL in your Python code. It is implemented automatically in the CPython interpreter and is active by default.
However, you can use the `threading` module ([docs](https://docs.python.org/3/library/threading.html)) to create and manage threads in your Python code:
```
import threading
def make_soda():
print("Making a delicious soda!")
if __name__ == "__main__":
t1 = threading.Thread(target=make_soda)
t2 = threading.Thread(target=make_soda)
t3 = threading.Thread(target=make_soda)
t1.start()
t2.start()
t3.start()
```
### Race condition
Imagine that you and your friends are making a batch of soda together. You've got all the ingredients ready to go — sugar, water, caramel coloring, and some secret spices.
But you all try to add the ingredients to the same pot at the same time. This can lead to unexpected results because you don't know which ingredients will be mixed in first. This is similar to a race condition in a program, where two or more threads try to modify the same shared resource at the same time\!
But because the GIL is in place, the other thread will have to wait for its turn before it can start making some fizzy goodness.
You may have already noticed — GIL may seem like a bottleneck because of this wait. But, it’s actually just there to keep things running smoothly.
### Input/Output (I/O) Bound
It is important to note that GIL does **not** affect programs that rely on I/O operations as these operations typically release the GIL while waiting for data to be transferred.
What exactly do you mean by I/O bound?
At its most basic, I/O bound means that a program is waiting for I/O operations to complete. This can include things like:
1. Reading from or writing to a file
2. Sending or receiving data over a network
3. Interacting with a user through a graphical user interface (GUI), etc.
Essentially, any time a program has to wait for something to happen outside of itself, it's probably doing I/O-bound work.
## The Debate
A TL;DR about all the fuss about the Global Interpreter Lock, or GIL.
### Supporters
> “The GIL is a great feature of Python! It makes it easy for us to write multi-threaded programs without having to worry about race conditions!” – says the supporters.
They argue that *most* Python programs aren’t CPU-intensive, to begin with. Most of the time, the programs are doing I/O-bound work which GIL doesn’t really affect. So, why all the fuss?
### Critics
> “The GIL is holding us back!” – say the critics with an opposite view.
With GIL, only one thread can execute Python bytecodes at a time.
As a result, this can limit the performance of CPU-bound Python programs on systems with multiple CPU cores. Because of this, GIL is known as a major limitation of Python.
Although most Python programs are I/O-bound, it doesn’t mean that we shouldn’t be able to write high-performance CPU-bound programs in Python.
## Conclusion
So who's right? Well, as with most debates, there's no easy answer.
The GIL may be a necessary compromise that makes it easy for Python programmers to write multi-threaded programs. Nevertheless, it can also limit the performance of CPU-bound programs on systems with multiple CPU cores.
The debate lives on, for now, I guess. Lastly, check out [this HN post and comments](https://news.ycombinator.com/item?id=28690560) if you're interested to dive a little bit deeper into the wonderful world of GIL. |
| Shard | 165 (laksa) |
| Root Hash | 4607163346904142165 |
| Unparsed URL | com,jerrynsh!/python-gil-explained-like-im-five/ s443 |