gh-130094: Fix race conditions in importlib (gh-130101)

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.

Some packages modify `sys.modules` during import. For example, `collections`
inserts the entry for `collections.abc`  into `sys.modules` during import. We
need to ensure that we re-check `sys.modules` *after* the parent module is
fully initialized.
This commit is contained in:
Sam Gross 2025-02-18 18:02:42 -05:00 committed by GitHub
parent 8207454bc0
commit 857bdba0ac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 14 additions and 3 deletions

View file

@ -0,0 +1,2 @@
Fix two race conditions involving concurrent imports that could lead to
spurious failures with :exc:`ModuleNotFoundError`.