Skip to content

Commit 3e1eedd

Browse files
gpsheadclaude
andcommitted
PySys_AddAuditHook: check initialized, not core_initialized
The docs say audit hooks are notified "after runtime initialization". With the flag move, initialized=0 throughout init (including site import), so hooks are correctly not invoked during any init phase. Using core_initialized would have expanded the invocation window beyond the original behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent efeae3b commit 3e1eedd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Python/sysmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Data members:
3333
#include "pycore_pymath.h" // _PY_SHORT_FLOAT_REPR
3434
#include "pycore_pymem.h" // _PyMem_DefaultRawFree()
3535
#include "pycore_pystate.h" // _PyThreadState_GET()
36-
#include "pycore_runtime.h" // _PyRuntimeState_GetCoreInitialized()
36+
#include "pycore_runtime.h" // _PyRuntimeState_GetInitialized()
3737
#include "pycore_pystats.h" // _Py_PrintSpecializationStats()
3838
#include "pycore_structseq.h" // _PyStructSequence_InitBuiltinWithFlags()
3939
#include "pycore_sysmodule.h" // export _PySys_GetSizeOf()
@@ -472,7 +472,7 @@ PySys_AddAuditHook(Py_AuditHookFunction hook, void *userData)
472472
PySys_AddAuditHook() can be called before Python is initialized. */
473473
_PyRuntimeState *runtime = &_PyRuntime;
474474
PyThreadState *tstate;
475-
if (_PyRuntimeState_GetCoreInitialized(runtime)) {
475+
if (_PyRuntimeState_GetInitialized(runtime)) {
476476
tstate = _PyThreadState_GET();
477477
}
478478
else {

0 commit comments

Comments
 (0)