]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-87135: Raise PythonFinalizationError when joining a blocked daemon thread (gh...
authorPetr Viktorin <encukou@gmail.com>
Mon, 28 Apr 2025 13:48:48 +0000 (15:48 +0200)
committerGitHub <noreply@github.com>
Mon, 28 Apr 2025 13:48:48 +0000 (15:48 +0200)
commit4ebbfcf30e0e2d87ff6036d4d1de0f6f0ef7c46a
treebd04a48591c2bc6fc6df81c0c4ab8e27addeba4d
parent995b1a72f20e4b0bc44b6471d40c2c368d74efb1
gh-87135: Raise PythonFinalizationError when joining a blocked daemon thread (gh-130402)

If `Py_IsFinalizing()` is true, non-daemon threads (other than the current one)
are done, and daemon threads are prevented from running, so they
cannot finalize themselves and become done. Joining them (without timeout)
would block forever.

Raise PythonFinalizationError instead of hanging.

Raise even when a timeout is given, for consistency with trying to join your own thread.

See gh-123940 for a use case: calling `join()` from `__del__`. This is
ill-advised, but an exception should at least make it easier to diagnose.
Doc/c-api/init.rst
Doc/library/exceptions.rst
Doc/library/threading.rst
Lib/test/test_threading.py
Misc/NEWS.d/next/Library/2025-02-21-15-46-43.gh-issue-130402.Rwu_KK.rst [new file with mode: 0644]
Modules/_threadmodule.c