August 30th, 2024

500 Python Interpreters

Python 3.13 will introduce an optional Global Interpreter Lock (GIL) to enhance multithreading performance, addressing historical limitations that affected applications like video games and presenting challenges for extension developers.

Read original articleLink Icon
CuriosityExcitementConcern
500 Python Interpreters

As Python 3.13 approaches its final release, discussions have intensified around the introduction of an optional Global Interpreter Lock (GIL) as outlined in PEP 703. This change aims to enhance Python's performance in multithreading, a long-awaited improvement for many users. The GIL has historically limited Python's ability to execute threads concurrently, impacting performance, particularly in applications like video games. The article reflects on the author's personal experiences with Python's GIL, tracing its origins back to Python 1.5 when threading was first introduced. The GIL was designed to simplify the C API and ensure thread safety, but it has also led to performance bottlenecks, especially in high-demand scenarios. The introduction of a per-interpreter GIL in Python 3.12 (PEP 684) and the upcoming optional GIL in 3.13 are seen as steps towards addressing these issues. The author emphasizes the historical context of Python's development, noting that early decisions were made without the benefit of extensive community input or established best practices. The article concludes by discussing how the GIL operates at the C API level and the implications for extension developers, highlighting the ongoing challenges and potential improvements in Python's threading model.

- Python 3.13 will introduce an optional GIL to improve multithreading performance.

- The GIL has historically limited Python's threading capabilities, affecting applications like video games.

- The introduction of a per-interpreter GIL in Python 3.12 is a step towards better performance.

- Early design decisions regarding the GIL were made without extensive community input.

- The GIL's operation at the C API level presents challenges for extension developers.

AI: What people are saying
The comments reflect a mix of excitement and skepticism regarding the introduction of the optional GIL in Python 3.13.
  • Users are curious about the practical implications of the new GIL, particularly for multithreading and performance gains.
  • There are questions about the stability and potential issues of the new implementation, with some users considering waiting before adopting it in new libraries.
  • Some comments reference technical details and jokes related to the GIL and interpreter states, indicating a mix of humor and confusion in the community.
  • Concerns about the complexity of debugging multithreaded applications with the new GIL are raised.
  • Overall, there is a strong interest in understanding the use cases and performance expectations of the new feature.
Link Icon 10 comments
By @jiggunjer - 8 months
So this means modules like concurrent.futures can create a thread pool object (as opposed to processpool) and run in parallel?

Or is the functionality as of 3.13 still limited to low level python embedding applications?

By @curious_cat_163 - 8 months
> "No matter what happens there is going to be a lock occurring. No two PyThreadStates can execute Python bytecode at the same time. However, they can execute multiple C calls at the same time which is why for long running pure C operations extension and embedding developers are encouraged to release the GIL temporarily."

Very exciting! I wonder what the first set of motivating applications are and what kind of performance gains are they expecting.

By @vintagedave - 8 months
> // 500 interpreter states

> static constexpr auto MAXIMUM_STATES = 463;

There is a joke here that I’m missing. Does anyone understand what it is?

By @jacob019 - 8 months
When they say per interpreter GIL in PEP 684, is that per thread? I wasn't aware of multiple interpreters in one process.
By @quasarj - 8 months
Is 463 some joke I'm not getting?
By @funny_falcon - 8 months
Unfortunately, pocketpy moved to global reference to vm recently while changing implementation from C++ to C. Weird decision.
By @elnatro - 8 months
Does this mean that even the Python 3.13 version is around the corner we have to expect some issues when running threads on a program?

Maybe I’m slow today, but are the author complaining (rightfully so) about the buggy no-gil implementation?

Should we wait until the feature is more stable before implementing new libraries? I was thinking on making use of it in new libraries I plan to develop.

What are the most blatant use case to test this feature?

PD: So many questions, I know, sorry everybody!

By @layer8 - 8 months
I was hoping for it to be an HTTP status code.
By @surfingdino - 8 months
I'm lo0king forward to it, but debugging this stuff is going to be another level of hard.
By @zahlman - 8 months
You posted this 11 days ago and it's been posted by two other people in the interim. (Why is this version of the post more popular?)