Skip to content

Commit fde9b33

Browse files
authored
bpo-36427: Document that PyEval_RestoreThread and PyGILState_Ensure can terminate the calling thread (GH-12541)
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.
1 parent 46544f6 commit fde9b33

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
created, the current thread must not have acquired it, otherwise deadlock
857857
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)