summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-10-24 22:12:51 (GMT)
committerGitHub <noreply@github.com>2024-10-24 22:12:51 (GMT)
commitfed501d7247053ce46a2ba512bf0e4bb4f483be6 (patch)
tree11005e6c0fd2af498b0eb019b26809aea672c2f9
parent332356b880576a1a00b5dc34f03d7d3995dd4512 (diff)
downloadcpython-fed501d7247053ce46a2ba512bf0e4bb4f483be6.zip
cpython-fed501d7247053ce46a2ba512bf0e4bb4f483be6.tar.gz
cpython-fed501d7247053ce46a2ba512bf0e4bb4f483be6.tar.bz2
gh-125245: Fix race condition when importing `collections.abc` (#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.
-rw-r--r--Lib/collections/__init__.py3
-rw-r--r--Lib/collections/abc.py3
-rw-r--r--Misc/NEWS.d/next/Library/2024-10-11-00-40-13.gh-issue-125245.8vReM-.rst2
3 files changed, 5 insertions, 3 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index b47e728..d688141 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -29,6 +29,9 @@ __all__ = [
import _collections_abc
import sys as _sys
+_sys.modules['collections.abc'] = _collections_abc
+abc = _collections_abc
+
from itertools import chain as _chain
from itertools import repeat as _repeat
from itertools import starmap as _starmap
diff --git a/Lib/collections/abc.py b/Lib/collections/abc.py
deleted file mode 100644
index 034ba37..0000000
--- a/Lib/collections/abc.py
+++ /dev/null
@@ -1,3 +0,0 @@
-import _collections_abc
-import sys
-sys.modules[__name__] = _collections_abc
diff --git a/Misc/NEWS.d/next/Library/2024-10-11-00-40-13.gh-issue-125245.8vReM-.rst b/Misc/NEWS.d/next/Library/2024-10-11-00-40-13.gh-issue-125245.8vReM-.rst
new file mode 100644
index 0000000..c880efe
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-10-11-00-40-13.gh-issue-125245.8vReM-.rst
@@ -0,0 +1,2 @@
+Fix race condition when importing :mod:`collections.abc`, which could
+incorrectly return an empty module.