[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 fed501d724)

Co-authored-by: Sam Gross <colesbury@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-10-25 00:38:45 +02:00 committed by GitHub
parent 92d301eb67
commit d46d291bd3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 3 deletions

View File

@ -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

View File

@ -1,3 +0,0 @@
import _collections_abc
import sys
sys.modules[__name__] = _collections_abc

View File

@ -0,0 +1,2 @@
Fix race condition when importing :mod:`collections.abc`, which could
incorrectly return an empty module.