summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Doc/c-api/init.rst4
-rw-r--r--Misc/NEWS.d/next/C API/2020-01-31-16-35-21.bpo-39511.nv9yEn.rst3
-rw-r--r--Python/pystate.c8
3 files changed, 12 insertions, 3 deletions
diff --git a/Doc/c-api/init.rst b/Doc/c-api/init.rst
index 7ea48aec00..14049ee642 100644
--- a/Doc/c-api/init.rst
+++ b/Doc/c-api/init.rst
@@ -1048,6 +1048,10 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
Reset all information in a thread state object. The global interpreter lock
must be held.
+ .. versionchanged:: 3.9
+ This function now calls the :c:member:`PyThreadState.on_delete` callback.
+ Previously, that happened in :c:func:`PyThreadState_Delete`.
+
.. c:function:: void PyThreadState_Delete(PyThreadState *tstate)
diff --git a/Misc/NEWS.d/next/C API/2020-01-31-16-35-21.bpo-39511.nv9yEn.rst b/Misc/NEWS.d/next/C API/2020-01-31-16-35-21.bpo-39511.nv9yEn.rst
new file mode 100644
index 0000000000..14a04875a8
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2020-01-31-16-35-21.bpo-39511.nv9yEn.rst
@@ -0,0 +1,3 @@
+The :c:func:`PyThreadState_Clear` function now calls the
+:c:member:`PyThreadState.on_delete` callback. Previously, that happened in
+:c:func:`PyThreadState_Delete`.
diff --git a/Python/pystate.c b/Python/pystate.c
index d792380de4..ebc17ea5a7 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -806,6 +806,10 @@ PyThreadState_Clear(PyThreadState *tstate)
Py_CLEAR(tstate->async_gen_finalizer);
Py_CLEAR(tstate->context);
+
+ if (tstate->on_delete != NULL) {
+ tstate->on_delete(tstate->on_delete_data);
+ }
}
@@ -830,9 +834,7 @@ tstate_delete_common(PyThreadState *tstate,
if (tstate->next)
tstate->next->prev = tstate->prev;
HEAD_UNLOCK(runtime);
- if (tstate->on_delete != NULL) {
- tstate->on_delete(tstate->on_delete_data);
- }
+
PyMem_RawFree(tstate);
if (gilstate->autoInterpreterState &&