From daa0fe03a517d335d48e65ace8e5da636e265a8f Mon Sep 17 00:00:00 2001 From: Konge Date: Sat, 4 Jul 2020 05:06:46 +0800 Subject: bpo-41162: Clear audit hooks later during finalization (GH-21222) --- Python/pylifecycle.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'Python') diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 3ce2c41ef1..2d219a4a3a 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1291,6 +1291,13 @@ finalize_interp_clear(PyThreadState *tstate) _PyGC_CollectNoFail(); } + /* Clear all loghooks */ + /* Both _PySys_Audit function and users still need PyObject, such as tuple. + Call _PySys_ClearAuditHooks when PyObject available. */ + if (is_main_interp) { + _PySys_ClearAuditHooks(tstate); + } + _PyGC_Fini(tstate); if (is_main_interp) { @@ -1405,9 +1412,6 @@ Py_FinalizeEx(void) */ _PyGC_CollectIfEnabled(); - /* Clear all loghooks */ - _PySys_ClearAuditHooks(tstate); - /* Destroy all modules */ _PyImport_Cleanup(tstate); -- cgit v1.2.1