cpython icon indicating copy to clipboard operation
cpython copied to clipboard

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

Open encukou opened this issue 6 months ago • 1 comments

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?

  • Issue: gh-87135

encukou avatar Jun 26 '25 14:06 encukou

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>

vstinner avatar Jun 26 '25 16:06 vstinner