Skip to content

Commit d46d291

Browse files
[3.13] gh-125245: Fix race condition when importing collections.abc (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 <[email protected]>
1 parent 92d301e commit d46d291

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

Lib/collections/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import _collections_abc
3030
import sys as _sys
3131

32+
_sys.modules['collections.abc'] = _collections_abc
33+
abc = _collections_abc
34+
3235
from itertools import chain as _chain
3336
from itertools import repeat as _repeat
3437
from itertools import starmap as _starmap

Lib/collections/abc.py

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix race condition when importing :mod:`collections.abc`, which could
2+
incorrectly return an empty module.

0 commit comments

Comments
 (0)