Skip to content

gh-158090: Fix hang at shutdown when a daemon thread resets the GIL drop request - #158101

Open
lazerg wants to merge 1 commit into
python:mainfrom
lazerg:fix-issue-158090
Open

lazerg wants to merge 1 commit into
python:mainfrom
lazerg:fix-issue-158090

Conversation

@lazerg

@lazerg lazerg commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

When a daemon thread in take_gil() sees that it must exit, it released gil->mutex before clearing the drop request it had set on the GIL holder. In that gap the holder could run drop_gil(), still see the bit set, and wait on switch_cond forever, since the only waiter was about to hang. Clearing the bit before releasing the mutex closes the window: the holder needs gil->mutex to drop the GIL, so it now always sees the bit already cleared.

I checked it with the lldb recipe from the issue on a --with-pydebug build. Before the change the process hangs with the main thread in drop_gil(). After it, stopping the daemon thread right after the unlock no longer hangs, and the process exits normally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant