You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 83b692b
Browse filesBrowse the repository at this point in the historyBrowse files
Fix free-threaded race reifying a lazy submodule attribute
A lazily imported submodule is tracked in two places: the binding on its
parent package, and the parent's entry in the interpreter's pending-submodule
map. Reading an attribute consults both, and nothing ordered the two updates
against each other, so in the free-threaded build:
1. Thread A looks up pkg.sub, misses it in pkg.__dict__, and falls through to
the lazy-submodule path.
2. Thread B gets there first: it imports pkg.sub, binds it on pkg, and removes
'sub' from pkg's pending set.
3. Thread A checks that set, finds the name gone, concludes 'sub' was never a
lazy submodule, and raises AttributeError for an attribute that by then
exists.
Make the parent's __dict__ authoritative and the pending set a hint that can
only go stale in one direction: _PyImport_TryLoadLazySubmodule() stores the
binding before dropping the name from the pending set, and re-reads the
parent's __dict__ when it finds the name already gone. A thread that observes
the removal is then guaranteed to see the binding.
Issue: pythongh-154561
0 commit comments