Add materials for What Is the Python Global Interpreter Lock (GIL)? - #842
Open
realpython-bot wants to merge 1 commit into
Open
realpython-bot wants to merge 1 commit into
realpython-bot wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New folder for a tutorial that never had one
This is a brand-new
python-gil/folder — the tutorial What Is the Python Global Interpreter Lock (GIL)? has never shipped companion code. That means this PR needs an editorial eye as well as a code review: someone should confirm the file names, the README framing, and the REPL-to-script conversions read the way the team wants them to before this is merged.The code was taken from the updated draft, not the live article:
What the folder contains, and how it maps to the article
reference_counting.pypyconREPL block (sys.getrefcount())single_threaded.pysingle_threaded.pymulti_threaded.pymulti_threaded.pyswitch_interval.pypyconREPL block (sys.getswitchinterval())multiprocess.pymultiprocess.pyREADME.mdThat is every code block in the article. Nothing was invented and no example was "improved" — the folder mirrors the tutorial.
REPL examples were turned into runnable scripts
The two
pyconblocks became plain.pyfiles thatprint()the value the prose is talking about, which is the convention in siblings likepython-set/andpython-list/. Article order and variable names are preserved (a,binreference_counting.py; the switch-interval comment is carried over verbatim). Each section's REPL sequence is one coherent script rather than one file per snippet — here each section only had a single short block, so that's one file each.Two deliberate deviations from the article text, both to pass the repo's gates
single_threaded.pydropsfrom threading import Thread. The article's listing importsThreadbut never uses it in the single-threaded version. The repo's ruff config (select = ["E", "F", "RUF100"]) flags that asF401andruff checkfails. The import is removed here. This is arguably a bug in the article too — worth fixing in draft 2346 so the two stay in sync.while n>0:;ruff formatnormalizes these to double quotes andwhile n > 0:. Logic, values, and structure are untouched.No
requirements.txtThe draft's
dependenciesfield ispython==3.14— no third-party packages. Per the repo convention for stdlib-only tutorials (python-deque/,python-repl/,python-set/,python-list/all do this), the folder ships norequirements.txt.How this was verified
Everything was actually executed — nothing was skipped, and nothing in this folder needs a server, a GUI, or a paid API key.
1. Ran every file in a fresh venv on the article's pin (CPython 3.14.6), with
MPLBACKEND=Aggexported:Checked against the article:
reference_counting.pyprints 3, exactly the value the article shows.switch_interval.pyprints 0.005, exactly the value the article shows.multiprocess.pyis the fastest (1.15s) but well short of halving the time, which is the article's point about process-management overhead. The README warns readers that these numbers are machine-dependent.2. The repo's own gates, at the version the root
requirements.txtpins (ruff==0.14.1):The folder name and its
README.mdalso satisfy.github/workflows/dircheck.py.Only
python-gil/is touched by this PR.git status --porcelainandgit clean -ndare both empty — no venvs, caches, or generated output.