PYTHONMALLOCSTATS=1 fails with fatal error at Python exit · Issue #111499 · python/cpython (original) (raw)
Py_FinalizeEx()
calls _PyObject_DebugMallocStats()
which calls indirectly _PyInterpreterState_GET()
. Problem: at this point, there is no "interpreter" anymore, and so _PyInterpreterState_GET()
fails with a fatal error.
$ PYTHONMALLOCSTATS=1 ./python -c pass
Small block threshold = 512, in 32 size classes.
(...)
Total = 262,144
Small block threshold = 512, in 32 size classes.
(...)
Total = 655,360
Fatal Python error: _PyInterpreterState_GET: the function must be called with the GIL held, after Python initialization and before Python finalization, but the GIL is released (the current Python thread state is NULL)
Python runtime state: finalizing (tstate=0x0000000000ae7550)
Abandon (core dumped)