From 926525dcdaa4c1764638751ffe1e43c5252cdbd0 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Mon, 25 Mar 2019 22:15:03 +0000 Subject: [PATCH 1/2] bpo-36427: Document that PyEval_RestoreThread and PyGILState_Ensure can terminate the calling thread --- Doc/c-api/init.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index 2c6d21fa9da187..9e263d0bdecb30 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -855,6 +855,12 @@ code, or when embedding the Python interpreter: created, the current thread must not have acquired it, otherwise deadlock ensues. + .. warning:: + Calling this function from a thread when the interpreter is finalizing + will terminate the thread, even if the thread was not created by Python. + You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to + check if the interpreter is in process of being finalized before calling + this function to avoid unwanted termination. .. c:function:: PyThreadState* PyThreadState_Get() @@ -902,6 +908,12 @@ with sub-interpreters: When the function returns, the current thread will hold the GIL and be able to call arbitrary Python code. Failure is a fatal error. + .. warning:: + Calling this function from a thread when the interpreter is finalizing + will terminate the thread, even if the thread was not created by Python. + You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to + check if the interpreter is in process of being finalized before calling + this function to avoid unwanted termination. .. c:function:: void PyGILState_Release(PyGILState_STATE) From 47fa8d0f7eb0b91cc337f6640b6d22754819c97c Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Sat, 13 Apr 2019 17:09:55 +0100 Subject: [PATCH 2/2] Use a note instead of a warning and s/interpreter/runtime --- Doc/c-api/init.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst index 9e263d0bdecb30..d9f99569a58e59 100644 --- a/Doc/c-api/init.rst +++ b/Doc/c-api/init.rst @@ -855,8 +855,8 @@ code, or when embedding the Python interpreter: created, the current thread must not have acquired it, otherwise deadlock ensues. - .. warning:: - Calling this function from a thread when the interpreter is finalizing + .. note:: + Calling this function from a thread when the runtime is finalizing will terminate the thread, even if the thread was not created by Python. You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to check if the interpreter is in process of being finalized before calling @@ -908,8 +908,8 @@ with sub-interpreters: When the function returns, the current thread will hold the GIL and be able to call arbitrary Python code. Failure is a fatal error. - .. warning:: - Calling this function from a thread when the interpreter is finalizing + .. note:: + Calling this function from a thread when the runtime is finalizing will terminate the thread, even if the thread was not created by Python. You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to check if the interpreter is in process of being finalized before calling