You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
importlib race condition allows stale module ref to escape on failure #143650
All three have an optimization that skips locking when a module appears already loaded, but none verify the module is still valid after checking _initializing.
Reproducer
importsysimportthreadingimporttempfileimportoswithtempfile.TemporaryDirectory() astmpdir:
sys.path.insert(0, tmpdir)
# Module that partially initializes then failswithopen(os.path.join(tmpdir, "failing_mod.py"), "w") asf:
f.write("import time; time.sleep(0.05); raise RuntimeError('fail')")
results= []
defdo_import(delay):
importtime; time.sleep(delay)
try:
mod=__import__("failing_mod")
if"failing_mod"notinsys.modules:
results.append("RACE: got module not in sys.modules")
exceptRuntimeError:
results.append("ok")
t1=threading.Thread(target=do_import, args=(0,))
t2=threading.Thread(target=do_import, args=(0.01,))
t1.start(); t2.start(); t1.join(); t2.join()
print(results) # May show "RACE" on affected builds
Activity
import numpyin two different threads can lead to race-condition #91238 as a duplicate of this issuegh-143650: Fix importlib race condition on import failure (GH-143651)
pythongh-143650: Fix importlib race condition on import failure (pyth…
[3.14] gh-143650: Fix importlib race condition on import failure (GH-…
pythongh-143650: Fix importlib race condition on import failure (pyth…
[3.13] gh-143650: Fix importlib race condition on import failure (GH-…
pythongh-143650: Fix importlib race condition on import failure (pyth…
pythongh-143650: Fix importlib race condition on import failure (pyth…
pythongh-143650: Fix importlib race condition on import failure (pyth…
fix(startup): remove background preloader daemon to stop import race