Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7723d05

Browse files
authored
[3.7] bpo-36427: Document that PyEval_RestoreThread and PyGILState_Ensure can terminate the calling thread (GH-12541) (GH-12820)
Calling these function from a thread when the runtime is finalizing will terminate the thread, even if the thread was not created by Python. Users can use _Py_IsFinalizing or sys.is_finalizing to check if the interpreter is in the process of being finalized before calling this function to avoid unwanted termination. (cherry picked from commit fde9b33)
1 parent f3a9d72 commit 7723d05

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Doc/c-api/init.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,12 @@ code, or when embedding the Python interpreter:
856856
*NULL*. If the lock has been created, the current thread must not have
857857
acquired it, otherwise deadlock ensues.
858858
859+
.. note::
860+
Calling this function from a thread when the runtime is finalizing
861+
will terminate the thread, even if the thread was not created by Python.
862+
You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to
863+
check if the interpreter is in process of being finalized before calling
864+
this function to avoid unwanted termination.
859865
860866
.. c:function:: PyThreadState* PyThreadState_Get()
861867
@@ -903,6 +909,12 @@ with sub-interpreters:
903909
When the function returns, the current thread will hold the GIL and be able
904910
to call arbitrary Python code. Failure is a fatal error.
905911
912+
.. note::
913+
Calling this function from a thread when the runtime is finalizing
914+
will terminate the thread, even if the thread was not created by Python.
915+
You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to
916+
check if the interpreter is in process of being finalized before calling
917+
this function to avoid unwanted termination.
906918
907919
.. c:function:: void PyGILState_Release(PyGILState_STATE)
908920

0 commit comments

Comments
 (0)