Skip to content

Commit 194beca

Browse files
committed
gh-130094: Fix race condition in _find_spec
Entries may be added or removed from `sys.meta_path` concurrently. For example, setuptools temporarily adds and removes the `distutils` finder from the beginning of the list. The local copy ensures that we don't skip over any entries.
1 parent 05e89c3 commit 194beca

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

Lib/importlib/_bootstrap.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,9 @@ def _find_spec(name, path, target=None):
12441244
raise ImportError("sys.meta_path is None, Python is likely "
12451245
"shutting down")
12461246

1247+
# gh-130094: copy sys.meta_path so that we have a consistent view of the
1248+
# list while iterating over it.
1249+
meta_path = list(meta_path)
12471250
if not meta_path:
12481251
_warnings.warn('sys.meta_path is empty', ImportWarning)
12491252

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TODO

Programs/test_frozenmain.h

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)