VOOZH about

URL: https://thenewstack.io/pythons-gil-multithreading-and-multiprocessing/

⇱ Python's GIL, Multithreading and Multiprocessing - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2024-10-19 07:00:45
Python's GIL, Multithreading and Multiprocessing
Programming Languages / Python / Software Development

Python’s GIL, Multithreading and Multiprocessing

This tutorial explains the Python global interpreter lock (GIL), which prevents multiple threads from executing Python code at the same time.
Oct 19th, 2024 7:00am by Jessica Wachtel
👁 Featued image for: Python’s GIL, Multithreading and Multiprocessing
Featured image via Unsplash+.

Programming languages aren’t necessarily controversial but Python’s Global Interpreter Lock (GIL) is a hotly debated topic. The GIL continues to bind Python’s thread of execution to one CPU causing bottlenecks and delays. So why do we still need the GIL and what’s the workaround?

What Is the GIL?

Python’s GIL, and Python as a language predates this multi-CPU world we live in currently. The first multicore processor was created in the early 2000s, about 10 years after the birth of Python. Before adding multiple cores to a machine was best practice, the premier way to speed up a system was to enhance the system’s single CPU. This meant that at the time of Python’s creation, the language was always tied to a single CPU.

Here’s where the GIL did (and does) came in handy. Python’s memory management isn’t thread-safe. This means two threads can’t access the same memory at the same time without risking data corruption. So even back in the days when all CPU bound tasks took place on a single CPU, it was imperative that not only was there order, but that the developer determined the order of operations rather than the CPU or luck. With the GIL acting as a giant lock, the thread of execution remained aligned with the developer’s plans and memory safety persists.

But now we live in a multicore world and Python is the language of choice for many compute heavy operations that might be better served by many CPUs so why not remove the GIL altogether? This process would require fundamental and breaking changes. Removing the GIL means changing Python memory handling.

Python Multiprocessing and Multithreading

Multiprocessing and multithreading are two ways to break the larger thread of execution into smaller threads.

Multithreading

For I/O intensive tasks, multithreading is a solid option. Multithreading is the process when a processor executes multiple threads concurrently. The threads run concurrently and parallel to one another on the same CPU, thus sharing the same memory space within a parent process. Multithreading saves system memory, increases computing speed, and improves application performance. Responsive UIs are a use case that frequently use multithreading.

Python supports multithreading via its threading module. The code snippet below includes the setup and execution of two threads.

numbers() and letters() both represent a task section that was separated into its own thread. The next step was to create a Thread object with the target function for execution. The `start()` method started each thread and the join() method waited for the threads to finish executing before moving the program forward.

There are downsides to multithreading. Multithreading is still bound by the GIL’s functionality.  The code itself can be more challenging to read leading to tougher troubleshooting and debugging processes. Multithreading processes can’t be interrupted.

Multiprocessing

Multiprocessing is how Python developers can work outside of the limitations of the GIL. This makes it a great choice for CPU intensive tasks. It’s more cost effective and efficient than single processor systems. Multiprocessing is similar to threading, but the workload is spread across multiple CPUs with each additional CPU furthering the speed, power, and memory capacity. Multiprocessing requires more memory storage than threads to move data between processes. An inter-process communication (IPC) model must be implemented to share objects between processes.

There’s also a Python module that supports multiprocessing. Though different than multithreading, the code looks very similar.

Fear not!

Even with the GIL you won’t have to process billions of data points one at a time with multithreading and multiprocessing on the job. Just a quick Google search will reveal thousands of searches about the GIL and who does/ doesn’t want it gone. It is by far Python’s most controversial topic.

TRENDING STORIES
Jessica Wachtel is a developer marketing writer at InfluxData where she creates content that helps make the world of time series data more understandable and accessible. Jessica has a background in software development and technical journalism.
Read more from Jessica Wachtel
SHARE THIS STORY
TRENDING STORIES
Google is a sponsor of The New Stack.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.