]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-87135: Hang non-main threads that attempt to acquire the GIL during finalization...
authorJeremy Maitin-Shepard <jeremy@jeremyms.com>
Wed, 2 Oct 2024 16:17:49 +0000 (09:17 -0700)
committerGitHub <noreply@github.com>
Wed, 2 Oct 2024 16:17:49 +0000 (09:17 -0700)
commit8cc5aa47ee464ddfd8da5461edecf4a5c72df2ff
tree41cdda0e2be153a4363cec9d616856444b306273
parent113b2d7583cdbf79da18e696f299a9aca24b599b
gh-87135: Hang non-main threads that attempt to acquire the GIL during finalization (GH-105805)

Instead of surprise crashes and memory corruption, we now hang threads that attempt to re-enter the Python interpreter after Python runtime finalization has started. These are typically daemon threads (our long standing mis-feature) but could also be threads spawned by extension modules that then try to call into Python. This marks the `PyThread_exit_thread` public C API as deprecated as there is no plausible safe way to accomplish that on any supported platform in the face of things like C++ code with finalizers anywhere on a thread's stack. Doing this was the least bad option.

Co-authored-by: Gregory P. Smith <greg@krypto.org>
Doc/c-api/init.rst
Include/internal/pycore_pythread.h
Include/pythread.h
Lib/test/test_threading.py
Misc/NEWS.d/next/C API/2022-08-05-19-41-20.gh-issue-87135.SCNBYj.rst [new file with mode: 0644]
Modules/_testcapimodule.c
Python/ceval_gil.c
Python/pylifecycle.c
Python/thread_nt.h
Python/thread_pthread.h