cpython/Lib/importlib
Miss Islington (bot) e60e7bdc92
[3.15] gh-159652: Fix import lock leak when the C stack is nearly exhausted (GH-159660) (GH-160779)
gh-159652: Fix import lock leak when the C stack is nearly exhausted (GH-159660)

When an import failed with a stack overflow RecursionError, releasing the import locks on the error path could itself raise RecursionError, because the cleanup runs in a new C frame. This left the global import lock or a module lock held forever, and later imports in other threads blocked indefinitely.

_imp.acquire_lock() now raises RecursionError when there is not enough stack left to release the lock. importlib calls it before taking any import lock, so this covers the per-module locks too. The module lock weakref callback skips cleanup in that case instead of
reporting an unraisable exception.
(cherry picked from commit 926b0bf311)

Co-authored-by: Cary Hawkins <hawkinscary23@gmail.com>
2026-10-27 22:17:27 +00:00
..
metadata
resources
__init__.py
_abc.py
_bootstrap.py [3.15] gh-159652: Fix import lock leak when the C stack is nearly exhausted (GH-159660) (GH-160779) 2026-10-27 22:17:27 +00:00
_bootstrap_external.py [3.15] gh-123011: Fix warn_explicit() with the globals of the __main__ module (GH-155318) (GH-155989) 2026-10-10 12:31:08 +03:00
abc.py
machinery.py
readers.py
simple.py
util.py