Skip to content

[3.15] gh-158820: Add null checks to avoid segfaults with lazy imports at shutdown (GH-158821) - #159062

Merged
JelleZijlstra merged 1 commit into
python:3.15from
miss-islington:backport-a6e6361-3.15
Oct 9, 2026
Merged

JelleZijlstra merged 1 commit into
python:3.15from
miss-islington:backport-a6e6361-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Destructors can run after finalization has cleared the interpreter's
lazy_modules set and lazy_pending_submodules dict. Declaring or
resolving a lazy import from one of them passed NULL to PySet_Add(),
PySet_Discard() or the pending-submodules lookup.

Treat the bookkeeping as a no-op once the state is gone, as the other
readers of this state already do.
(cherry picked from commit a6e6361)

Co-authored-by: Brittany Reynoso breynoso@meta.com

… at shutdown (pythonGH-158821)

Destructors can run after finalization has cleared the interpreter's
lazy_modules set and lazy_pending_submodules dict. Declaring or
resolving a lazy import from one of them passed NULL to PySet_Add(),
PySet_Discard() or the pending-submodules lookup.

Treat the bookkeeping as a no-op once the state is gone, as the other
readers of this state already do.
(cherry picked from commit a6e6361)

Co-authored-by: Brittany Reynoso <breynoso@meta.com>
@brittanyrey

Copy link
Copy Markdown
Contributor

@JelleZijlstra This should probably end up in 3.15.1 as well.

@JelleZijlstra
JelleZijlstra merged commit f8375c2 into python:3.15 Oct 9, 2026
55 checks passed
@miss-islington
miss-islington deleted the backport-a6e6361-3.15 branch October 9, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants