mirror of
https://github.com/python/cpython.git
synced 2025-07-09 20:35:26 +00:00
bpo-39511: PyThreadState_Clear() calls on_delete (GH-18296)
PyThreadState.on_delete is a callback used to notify Python when a thread completes. _thread._set_sentinel() function creates a lock which is released when the thread completes. It sets on_delete callback to the internal release_sentinel() function. This lock is known as Threading._tstate_lock in the threading module. The release_sentinel() function uses the Python C API. The problem is that on_delete is called late in the Python finalization, when the C API is no longer fully working. The PyThreadState_Clear() function now calls the PyThreadState.on_delete callback. Previously, that happened in PyThreadState_Delete(). The release_sentinel() function is now called when the C API is still fully working.
This commit is contained in:
parent
7dc140126e
commit
4d96b4635a
3 changed files with 12 additions and 3 deletions
|
@ -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 &&
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue