gh-87135: threading.Lock: Raise rather than hang on Python finalization by encukou · Pull Request #135991 · python/cpython · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

gh-87135: threading.Lock: Raise rather than hang on Python finalization #135991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 1, 2025

Conversation

encukou
Copy link
Member

@encukou encukou commented Jun 26, 2025

After Python finalization gets to the point where no other thread can attach thread state, attempting to acquire a Python lock will hang.
Raise PythonFinalizationError instead of hanging.

@colesbury, does this look maintainable (and correct) to you?

…lization

After Python finalization gets to the point where no other thread
can attach thread state, attempting to acquire a Python lock must
hang.
Raise PythonFinalizationError instead of hanging.
Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this approach makes sense. A comment about the flags below

@vstinner
Copy link
Member

Tests / Windows (free-threading) / Build and test (arm64) (pull_request)
Tests / Windows (free-threading) / Build and test (x64) (pull_request)

There is a suspicious error when running test.test_multiprocessing_spawn.test_processes:

Assertion failed: !PyErr_Occurred(), file D:\a\cpython\cpython\Python\specialize.c, line 740
Fatal Python error: Aborted

<Cannot show all threads while the GIL is disabled>
Stack (most recent call first):
  File "D:\a\cpython\cpython\Lib\logging\__init__.py", line 891 in _removeHandlerRef

Current thread's C stack trace (most recent call first):
  <cannot get C stack on this system>

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@encukou encukou merged commit fe119a0 into python:main Jul 1, 2025
44 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in MEDX-arabic-programme Jul 1, 2025
@encukou encukou deleted the no-acquire-in-finalize branch July 1, 2025 08:57
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.

4 participants

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.