Skip to content

Move the unref to below the multi-interpreter check. - #6195

Open
b-pass wants to merge 1 commit into
pybind:masterfrom
b-pass:multi-interp-import-segv
Open

b-pass wants to merge 1 commit into
pybind:masterfrom
b-pass:multi-interp-import-segv

Conversation

@b-pass

@b-pass b-pass commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

Description

This is a fix for #6174.

AI's assessment seems plausible

Thread A observes has_seen_non_main_interpreter() == false in get_pp() and prepares to return internals_singleton_pp_.
A non-main-interpreter thread B enters ensure_internals(), still observes the flag as false in unref(), and clears internals_singleton_pp_.
Thread A returns the now-null shared member.

Publishing has_seen_non_main_interpreter() = true before calling unref() in a non-main interpreter would cause that unref() to clear only the thread-local cache instead of the shared singleton.

Moving the unref makes sense. We cannot outright remove the unref, there is a case (covered by the "Restart the interpreter" unit test) which crashes without it.

Suggested changelog entry:

  • Fixed occasional test failure under heavy threading load (especially on windows)

@b-pass
b-pass requested a review from rwgk October 6, 2026 00:59
@b-pass b-pass self-assigned this Oct 6, 2026

This branch has not been deployed

No deployments
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.

1 participant