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.
This commit is contained in:
Pablo Galindo 2019-04-13 17:23:24 +01:00 committed by GitHub
parent 46544f69bf
commit fde9b33dfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -856,6 +856,12 @@ code, or when embedding the Python interpreter:
created, the current thread must not have acquired it, otherwise deadlock created, the current thread must not have acquired it, otherwise deadlock
ensues. ensues.
.. 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
this function to avoid unwanted termination.
.. c:function:: PyThreadState* PyThreadState_Get() .. c:function:: PyThreadState* PyThreadState_Get()
@ -903,6 +909,12 @@ with sub-interpreters:
When the function returns, the current thread will hold the GIL and be able When the function returns, the current thread will hold the GIL and be able
to call arbitrary Python code. Failure is a fatal error. to call arbitrary Python code. Failure is a fatal error.
.. 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
this function to avoid unwanted termination.
.. c:function:: void PyGILState_Release(PyGILState_STATE) .. c:function:: void PyGILState_Release(PyGILState_STATE)