-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-125245: Fix race condition when importing collections.abc
#125415
Conversation
If multiple threads concurrently imported `collections.abc`, some of the threads might incorrectly see the "shim" `Lib/collections/abc.py` module instead of the correct `Lib/_collections_abc.py` module. This was observed in the free threading build, but could, in theory, occur in the default GIL-enabled build as well.
This strategy won't work for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
The side effect is that user no longer needs to import collections.abc
explicitly if they imported collections
. It will be hard to change this back because users will write code that depends on this. Is it fine? cc @rhettinger
I applied this patch onto the 3.13 branch and I'm no longer able to reproduce the error I reported in #125245 by running the PyO3 tests repeatedly. |
We have other modules that do this (e.g. |
Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
…ythonGH-125415) If multiple threads concurrently imported `collections.abc`, some of the threads might incorrectly see the "shim" `Lib/collections/abc.py` module instead of the correct `Lib/_collections_abc.py` module. This affected both the free threading build and the default GIL-enabled build. (cherry picked from commit fed501d) Co-authored-by: Sam Gross <colesbury@gmail.com>
GH-125944 is a backport of this pull request to the 3.13 branch. |
…GH-125415) (GH-125944) If multiple threads concurrently imported `collections.abc`, some of the threads might incorrectly see the "shim" `Lib/collections/abc.py` module instead of the correct `Lib/_collections_abc.py` module. This affected both the free threading build and the default GIL-enabled build. (cherry picked from commit fed501d) Co-authored-by: Sam Gross <colesbury@gmail.com>
Refs python/cpython#125415 (cherry picked from commit fe01bda)
Refs python/cpython#125415 (cherry picked from commit fe01bda)
…ython#125415) If multiple threads concurrently imported `collections.abc`, some of the threads might incorrectly see the "shim" `Lib/collections/abc.py` module instead of the correct `Lib/_collections_abc.py` module. This affected both the free threading build and the default GIL-enabled build.
If multiple threads concurrently imported
collections.abc
, some of the threads might incorrectly see the "shim"Lib/collections/abc.py
module instead of the correctLib/_collections_abc.py
module. This was observed in the free threading build, but could, in theory, occur in the default GIL-enabled build as well.collections.abc
#125245