Skip to content

PYTHONMALLOCSTATS=1 fails with fatal error at Python exit #111499

Closed
@vstinner

Description

@vstinner

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:

$ 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)

cc @ericsnowcurrently

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12bugs and security fixes3.13bugs and security fixestopic-subinterpreterstype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions