← 返回首页
[3.13] gh-118727: Don't drop the GIL in `drop_gil()` unless the current thread holds it (GH-118745) by miss-islington · Pull Request #119474 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

[3.13] gh-118727: Don't drop the GIL in drop_gil() unless the current thread holds it (GH-118745)#119474

Merged
colesbury merged 1 commit into
python:3.13from
miss-islington:backport-be1dfcc-3.13
May 23, 2024
Merged

[3.13] gh-118727: Don't drop the GIL in drop_gil() unless the current thread holds it (GH-118745)#119474
colesbury merged 1 commit into
python:3.13from
miss-islington:backport-be1dfcc-3.13

Conversation

miss-islington commented May 23, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

drop_gil() assumes that its caller is attached, which means that the current
thread holds the GIL if and only if the GIL is enabled, and the enabled-state
of the GIL won't change. This isn't true, though, because detach_thread()
calls _PyEval_ReleaseLock() after detaching and
_PyThreadState_DeleteCurrent() calls it after removing the current thread
from consideration for stop-the-world requests (effectively detaching it).

Fix this by remembering whether or not a thread acquired the GIL when it last
attached, in PyThreadState._status.holds_gil, and check this in drop_gil()
instead of gil->enabled.

This fixes a crash in test_multiprocessing_pool_circular_import(), so I've
reenabled it.
(cherry picked from commit be1dfcc)

Co-authored-by: Brett Simmers swtaarrs@users.noreply.github.com

…t thread holds it (pythonGH-118745) `drop_gil()` assumes that its caller is attached, which means that the current thread holds the GIL if and only if the GIL is enabled, and the enabled-state of the GIL won't change. This isn't true, though, because `detach_thread()` calls `_PyEval_ReleaseLock()` after detaching and `_PyThreadState_DeleteCurrent()` calls it after removing the current thread from consideration for stop-the-world requests (effectively detaching it). Fix this by remembering whether or not a thread acquired the GIL when it last attached, in `PyThreadState._status.holds_gil`, and check this in `drop_gil()` instead of `gil->enabled`. This fixes a crash in `test_multiprocessing_pool_circular_import()`, so I've reenabled it. (cherry picked from commit be1dfcc) Co-authored-by: Brett Simmers <swtaarrs@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

3 participants

Footer

© 2026 GitHub, Inc.