diff --git a/peps/pep-0788.rst b/peps/pep-0788.rst index 3749258244d..0f5b58e1804 100644 --- a/peps/pep-0788.rst +++ b/peps/pep-0788.rst @@ -23,7 +23,7 @@ become problematic: - They aren't safe for finalization, either causing the calling thread to hang or crashing it with a segmentation fault, preventing further execution. - When they're called before finalization, they force the thread to be - "daemon", meaning that the interpreter won't wait for it to reach any point + "daemon", meaning that an interpreter won't wait for it to reach any point of execution. This is mostly frustrating for developers, but can lead to deadlocks! - Subinterpreters don't play nicely with them, because they all assume that @@ -54,12 +54,12 @@ This is achieved by introducing two concepts into the C API: - "Daemon" and "non-daemon" threads, similar to how it works in the :mod:`threading` module. -- Interpreter reference counts which prevent the interpreter from finalizing. +- Interpreter reference counts which prevent an interpreter from finalizing. In :c:func:`PyThreadState_Ensure`, both of these ideas are applied. The -calling thread is to store a reference to the interpreter via +calling thread is to store a reference to an interpreter via :c:func:`PyInterpreterState_Hold`. :c:func:`PyInterpreterState_Hold` -increases the reference count of the interpreter, requiring the thread +increases the reference count of an interpreter, requiring the thread to finish (by eventually calling :c:func:`PyThreadState_Release`) before beginning finalization. @@ -168,6 +168,8 @@ finalization, because a daemon thread got hung while holding the lock. There are workarounds for this for pure-Python code, but native threads don't have such an option. +.. _pep-788-hanging-compat: + We can't change finalization behavior for ``PyGILState_Ensure`` *************************************************************** @@ -186,6 +188,11 @@ error, as noted in `python/cpython#124622