-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Parallel import of modules causes a ModuleNotFoundError #130094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm seeing failures in the GIL-enabled build too (3.14.0a5 from uv). I made some slight modifications to the script to exit on error and set https://gist.github.com/colesbury/90493ef5b6f818bbbfde6922ffc8ea8a
|
One race condition is in setuptools, which can add and removes entries in cpython/Lib/importlib/_bootstrap.py Lines 1254 to 1262 in 05e89c3
We should probably make a copy of |
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.
@eendebakpt - can you try the linked PR (#130101) and verify that it fixes the issue? I haven't seen any import errors locally with it anymore. |
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 should be fixed in main now. |
Bug report
Bug description:
Using the free-threading build parallel import of modules causes a
ModuleNotFoundError
. The module that cannot be found can differ. A minimal reproducer:Note: this script fails on my system about 1 in 4 times. Changing the modules imported (or the order, or the number of threads) can effect this.
Modules that have given issues:
collections.abs
,glob
,sympy
,django.utils.regex_helper
. This suggests it is a general issue, and not a particular package.CPython versions tested on:
CPython main branch
Operating systems tested on:
Windows
Linked PRs
importlib
#130101The text was updated successfully, but these errors were encountered: