Fundamentals 5 min read

Will Python Finally Ditch the GIL? Inside the Upcoming 3.13 Changes

The article explains how Python's CPython interpreter is set to make the Global Interpreter Lock optional through PEP 703, detailing the recent merge that adds PYTHON_GIL=0 support, the expected Python 3.13 release date, and the potential impact on concurrency and AI workloads.

21CTO
21CTO
21CTO
Will Python Finally Ditch the GIL? Inside the Upcoming 3.13 Changes
Python is accelerating its development by planning to remove the long‑standing Global Interpreter Lock (GIL) in the upcoming CPython 3.13 release.

In CPython, the GIL is a mutex that protects access to Python objects, preventing multiple threads from executing bytecode simultaneously because CPython's memory management is not thread‑safe.

Over time, many features and multithreaded programs have become dependent on the GIL, creating a bottleneck for concurrent execution.

Good news: code that disables the GIL has been merged into the main branch this week, introducing support for PYTHON_GIL=0 or -X gil=0 when using a free‑threaded build.

The related Python Enhancement Proposal is PEP 703, which makes the GIL optional. The Python Steering Council has accepted the proposal and plans to ship it in Python 3.13, with a gradual rollout that minimizes disruption and allows rollback of any breaking changes.

PEP 703 cites DeepMind engineers who report that even with fewer than ten threads, the GIL becomes a performance bottleneck for workloads that would benefit from 50‑100 threads per process. The usual workaround—moving code to native extensions—makes development harder.

The proposal also notes that the GIL complicates deployment of AI models, a critical concern given the surge in interest in artificial‑intelligence software.

Brett Simmers, a Python core developer, warns that disabling the GIL will initially break existing code and that extensive testing (e.g., running the full test_asyncio suite) may cause crashes when PYTHON_GIL=0 is set.

Meta engineer Sam Gross, a major advocate of the change, says the default should remain enabled in free‑threaded builds until the transition is stable, and suggests adding a Py_mod_gil slot to allow selective disabling.

Support for the Py_mod_gil slot is in progress; if the gil parameter is omitted, the interpreter will pause all threads and re‑enable the GIL, which may reduce performance and trigger warnings.

In summary, Python 3.13, scheduled for release on 1 October 2024, will include the optional‑GIL feature, marking a significant shift in how Python handles concurrency.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonconcurrencyGILPEP703
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.