Skip to content

Commit 50850e0

Browse files
colesburyebonnal
authored andcommitted
pythongh-125245: Fix race condition when importing collections.abc (python#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.
1 parent bd8c83e commit 50850e0

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)