-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixestopic-subinterpreterstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
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)
Linked PRs
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixestopic-subinterpreterstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Milestone
Relationships
Development
Select code repository
Activity
vstinner commentedon Dec 20, 2023
Apparently, nobody cares nor uses this feature which has no test. I just close the issue. I don't have the bandwidth to work on a fix.
ShahriyarR commentedon Dec 26, 2023
Not sure if this is the related information or not, added here for future reference.
I got the same error with Python 3.12 while doing some tests.
Compiled Python as described here:
https://devguide.python.org/
Test:
Basically, the fix is calling Py_Initialize() before:
The difference is, in Python 3.9 I got sissegv instead of this Fatal error.
devdanzin commentedon Jun 4, 2024
I'm trying to add a test as part of #120006, but having segfaults (Linux) or non-zero process exit codes (Windows) is kinda getting in the way. Could this issue be reopened so other devs can attempt to solve it?
It seems the error has changed between versions:
Python 3.12.3 (Linux), non-debug build:
Python 3.14.0a0 (heads/main:6e012ced6c) (Linux), non-debug build:
The fix might be as simple as (pardon my C):
pythongh-111499: Fix PYTHONMALLOCSTATS at Python exit
pythongh-111499: Fix PYTHONMALLOCSTATS at Python exit
vstinner commentedon Jun 4, 2024
I wrote PR gh-120021 to fix the issue.
gh-111499: Fix PYTHONMALLOCSTATS at Python exit (#120021)
9 remaining items