@@ -863,6 +863,7 @@ code, or when embedding the Python interpreter:
863
863
check if the interpreter is in process of being finalized before calling
864
864
this function to avoid unwanted termination.
865
865
866
+
866
867
.. c:function:: PyThreadState* PyThreadState_Get()
867
868
868
869
Return the current thread state. The global interpreter lock must be held.
@@ -1080,9 +1081,27 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
1080
1081
*tstate *, which should not be *NULL *. The lock must have been created earlier.
1081
1082
If this thread already has the lock, deadlock ensues.
1082
1083
1084
+ .. note ::
1085
+ Calling this function from a thread when the runtime is finalizing
1086
+ will terminate the thread, even if the thread was not created by Python.
1087
+ You can use :c:func: `_Py_IsFinalizing ` or :func: `sys.is_finalizing ` to
1088
+ check if the interpreter is in process of being finalized before calling
1089
+ this function to avoid unwanted termination.
1090
+
1091
+ .. versionchanged :: 3.8
1092
+ Updated to be consistent with :c:func: `PyEval_RestoreThread `,
1093
+ :c:func: `Py_END_ALLOW_THREADS `, and :c:func: `PyGILState_Ensure `,
1094
+ and terminate the current thread if called while the interpreter is finalizing.
1095
+
1083
1096
:c:func: `PyEval_RestoreThread ` is a higher-level function which is always
1084
1097
available (even when threads have not been initialized).
1085
1098
1099
+ .. note::
1100
+ Calling this function from a thread when the runtime is finalizing
1101
+ will terminate the thread, even if the thread was not created by Python.
1102
+ You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to
1103
+ check if the interpreter is in process of being finalized before calling
1104
+ this function to avoid unwanted termination.
1086
1105
1087
1106
.. c:function:: void PyEval_ReleaseThread(PyThreadState *tstate)
1088
1107
@@ -1106,6 +1125,18 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
1106
1125
:c:func:`PyEval_RestoreThread` or :c:func:`PyEval_AcquireThread`
1107
1126
instead.
1108
1127
1128
+ .. note::
1129
+ Calling this function from a thread when the runtime is finalizing
1130
+ will terminate the thread, even if the thread was not created by Python.
1131
+ You can use :c:func:`_Py_IsFinalizing` or :func:`sys.is_finalizing` to
1132
+ check if the interpreter is in process of being finalized before calling
1133
+ this function to avoid unwanted termination.
1134
+
1135
+ .. versionchanged:: 3.8
1136
+ Updated to be consistent with :c:func:`PyEval_RestoreThread`,
1137
+ :c:func:`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`,
1138
+ and terminate the current thread if called while the interpreter is finalizing.
1139
+
1109
1140
1110
1141
.. c:function:: void PyEval_ReleaseLock()
1111
1142
0 commit comments