gh-129185: Simplify PyTraceMalloc_Track() (#129256)

Since tracemalloc uses PyMutex, it becomes safe to use TABLES_LOCK()
even after _PyTraceMalloc_Fini(): remove the "pre-check" in
PyTraceMalloc_Track() and PyTraceMalloc_Untrack().

PyTraceMalloc_Untrack() no longer needs to acquire the GIL.

_PyTraceMalloc_Fini() can be called earlier during Python
finalization.
This commit is contained in:
Victor Stinner 2025-01-24 14:29:36 +01:00 committed by GitHub
parent 233fd00f0a
commit fc6bc1e4e3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 26 deletions

View file

@ -2113,7 +2113,7 @@ _Py_Finalize(_PyRuntimeState *runtime)
/* Disable tracemalloc after all Python objects have been destroyed,
so it is possible to use tracemalloc in objects destructor. */
_PyTraceMalloc_Stop();
_PyTraceMalloc_Fini();
/* Finalize any remaining import state */
// XXX Move these up to where finalize_modules() is currently.
@ -2166,7 +2166,6 @@ _Py_Finalize(_PyRuntimeState *runtime)
finalize_interp_clear(tstate);
_PyTraceMalloc_Fini();
#ifdef Py_TRACE_REFS
/* Display addresses (& refcnts) of all objects still alive.