Skip to content

Commit 5fdd49d

Browse files
authored
gh-99377: Revert audit events for thread state creation and free, because the GIL is not properly held at these times (GH-99543)
1 parent bc390dd commit 5fdd49d

File tree

3 files changed

+1
-39
lines changed

3 files changed

+1
-39
lines changed

Doc/c-api/init.rst

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,25 +1239,12 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
12391239
The global interpreter lock need not be held, but may be held if it is
12401240
necessary to serialize calls to this function.
12411241
1242-
.. audit-event:: cpython.PyThreadState_New id c.PyThreadState_New
1243-
1244-
Raise an auditing event ``cpython.PyThreadState_New`` with Python's thread
1245-
id as the argument. The event will be raised from the thread creating the new
1246-
``PyThreadState``, which may not be the new thread.
1247-
12481242
12491243
.. c:function:: void PyThreadState_Clear(PyThreadState *tstate)
12501244
12511245
Reset all information in a thread state object. The global interpreter lock
12521246
must be held.
12531247
1254-
.. audit-event:: cpython.PyThreadState_Clear id c.PyThreadState_Clear
1255-
1256-
Raise an auditing event ``cpython.PyThreadState_Clear`` with Python's
1257-
thread id as the argument. The event may be raised from a different thread
1258-
than the one being cleared. Exceptions raised from a hook will be treated
1259-
as unraisable and will not abort the operation.
1260-
12611248
.. versionchanged:: 3.9
12621249
This function now calls the :c:member:`PyThreadState.on_delete` callback.
12631250
Previously, that happened in :c:func:`PyThreadState_Delete`.

Lib/test/test_audit.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,11 @@ def test_threading(self):
197197
actual = [(ev[0], ev[2]) for ev in events]
198198
expected = [
199199
("_thread.start_new_thread", "(<test_func>, (), None)"),
200-
("cpython.PyThreadState_New", "(2,)"),
201200
("test.test_func", "()"),
202-
("cpython.PyThreadState_Clear", "(2,)"),
203201
]
204202

205203
self.assertEqual(actual, expected)
206204

207-
def test_threading_abort(self):
208-
# Ensures that aborting PyThreadState_New raises the correct exception
209-
returncode, events, stderr = self.run_python("test_threading_abort")
210-
if returncode:
211-
self.fail(stderr)
212-
213205

214206
def test_wmi_exec_query(self):
215207
import_helper.import_module("_wmi")

Python/pystate.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -875,27 +875,14 @@ PyThreadState_New(PyInterpreterState *interp)
875875
PyThreadState *tstate = new_threadstate(interp);
876876
if (tstate) {
877877
_PyThreadState_SetCurrent(tstate);
878-
if (PySys_Audit("cpython.PyThreadState_New", "K", tstate->id) < 0) {
879-
PyThreadState_Clear(tstate);
880-
_PyThreadState_DeleteCurrent(tstate);
881-
return NULL;
882-
}
883878
}
884879
return tstate;
885880
}
886881

887882
PyThreadState *
888883
_PyThreadState_Prealloc(PyInterpreterState *interp)
889884
{
890-
PyThreadState *tstate = new_threadstate(interp);
891-
if (tstate) {
892-
if (PySys_Audit("cpython.PyThreadState_New", "K", tstate->id) < 0) {
893-
PyThreadState_Clear(tstate);
894-
_PyThreadState_Delete(tstate, 0);
895-
return NULL;
896-
}
897-
}
898-
return tstate;
885+
return new_threadstate(interp);
899886
}
900887

901888
// We keep this around for (accidental) stable ABI compatibility.
@@ -1043,10 +1030,6 @@ _PyInterpreterState_ClearModules(PyInterpreterState *interp)
10431030
void
10441031
PyThreadState_Clear(PyThreadState *tstate)
10451032
{
1046-
if (PySys_Audit("cpython.PyThreadState_Clear", "K", tstate->id) < 0) {
1047-
PyErr_WriteUnraisable(NULL);
1048-
}
1049-
10501033
int verbose = _PyInterpreterState_GetConfig(tstate->interp)->verbose;
10511034

10521035
if (verbose && tstate->cframe->current_frame != NULL) {

0 commit comments

Comments
 (0)