Repository navigation
fix(utilities): a concurrent first import on free-threaded 3.14t still keeps a layer raw for 'dictionary changed size during iteration' (#3243) - #3245
Merged
Conversation
…l keeps a layer raw for 'dictionary changed size during iteration' (#3243) - infoclass, schema: a class left unfinalised at definition, such as OrderedMultiInfo, is finalised by its first construction, which walks dir() over the MRO and then writes the class's namespace. Two threads constructing it at once each walk while the other writes, which raises on free-threaded CPython; Info.__new__ and Schema.__new__ now finalise under import_lock and re-read the state once they hold it. - importlib: import_lock's docs name the new holder. - tests: a thread's walk paused part way through while a second first construction runs, for Info and for Schema. tests/corekit, tests/protocols/schema, tests/utilities, tests/project, tests/protocols/*.py and tests/*.py pass, bar a conda gate test that fails the same on develop.
JarryShaw
force-pushed
the
fix/3243-free-threaded-first-import-race
branch
from
November 30, 2026 06:27
ef2b3f3 to
cb3ba7b
Compare
Owner
Author
|
Good to go at
|
Contributor
|
Coverage: 94.98% (unit tier, Python 3.15,
Per-file detail: the |
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.
Please follow the guide below
Put an
xinto every box [ ] that applies to your pull request (like this: [x])Use the Preview tab to see how your pull request will look
Searched for similar pull requests
Followed the coding style (
make pylint,make mypy,make isort)make testpasses, and a test case covers the changeDescribed the user-visible change below and left its changelog entry to the maintainer, keeping
docs/source/changelog/andCHANGELOG.mdout of the diff, if the change is user-visible: N/A — centralisedWhat is the purpose of your pull request?
Tick the commit type your subject line carries.
fix— corrects a defectfeat— adds a featureperf— changes performance, not behaviourrefactor— changes neither behaviour nor performancetest— tests onlydocs— documentation onlyci— workflows or build toolingrelease— bumps the version or rolls up a distributionchore— anything elseAlso tick if it regenerates constant or registry tables, members keeping their numeric values (the
constlabel)Description of your pull request and other information
Reproduced on a local free-threaded 3.14.10 (1 of 200 helper trials under load). The traceback runs from TCP's next layer through
HTTPv1.readand_freezeto the firstOrderedMultiInfo(...), thenInfo.__new__→info_final→dir(obj). A class left unfinalised at definition is finalised by its first construction, which walksdir()over the MRO and then writes the class's namespace. Two threads building it at once each walk while the other writes.Schema.__new__does the same.Info.__new__andSchema.__new__now finalise underimport_lockand re-read the state once they hold it. Every first import and nested-type store (fix(utilities): a concurrent first import can raise 'dictionary changed size during iteration' on PyPy #2870) already holds that lock, so no namespace is written while another thread walks it, and a class is finalised once. A finalised class takes no lock. No module finalises a class on import (none of 932), so the lock cannot wait inside an import.tests/corekit/test_first_construction_threads_3243_unit.pypauses one thread's walk while a second first construction runs, forInfoandSchema. Both fail on anorigin/developexport withRuntimeError('dictionary changed size during iteration'), on 3.14 and 3.14t, and pass with the fix.tests/corekit,tests/protocols/schema,tests/utilities,tests/project(bartest_conda_dev_release_gate_2458, which fails the same on the develop export),tests/protocols/*.py,tests/*.pyand the Sphinx-gated modules pass. pylint, mypy and isort raise nothing new.Closes #3243