$ 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)
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.It's a regression introduced by commit df3173d. Python 3.12 is also affected.
Reproducer:
cc @ericsnowcurrently
Linked PRs