Skip to content

Conversation

@encukou
Copy link
Member

@encukouencukou 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

@colesburycolesbury 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

@vstinnervstinner left a comment

Choose a reason for hiding this comment

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

LGTM

@encukouencukou merged commit fe119a0 into python:mainJul 1, 2025
44 checks passed
@encukouencukou deleted the no-acquire-in-finalize branch July 1, 2025 08:57
AndPuQing pushed a commit to AndPuQing/cpython that referenced this pull request Jul 11, 2025
…lization (pythonGH-135991) 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.
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
…lization (pythonGH-135991) 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.
picnixz pushed a commit to picnixz/cpython that referenced this pull request Jul 13, 2025
…lization (pythonGH-135991) 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.
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
…lization (pythonGH-135991) 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.
Agent-Hellboy pushed a commit to Agent-Hellboy/cpython that referenced this pull request Aug 19, 2025
…lization (pythonGH-135991) 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.
Sign up for freeto 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

@encukou@vstinner@colesbury@ZeroIntensity