-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PYTHONMALLOCSTATS=1 fails with fatal error at Python exit #111499
Comments
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. |
Not sure if this is the related information or not, added here for future reference. Test:
Basically, the fix is calling Py_Initialize() before:
The difference is, in Python 3.9 I got sissegv instead of this Fatal error. |
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: Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7ac632a in _PyInterpreterState_GET () at ./Include/internal/pycore_pystate.h:133
133 return tstate->interp; Python 3.14.0a0 (heads/main:6e012ced6c) (Linux), non-debug build: Program received signal SIGSEGV, Segmentation fault.
0x00005555556b0e3c in get_state () at Objects/obmalloc.c:1368
1368 return interp->obmalloc; The fix might be as simple as (pardon my C): diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c
index 4fe195b631..04e24bd407 100644
--- a/Objects/obmalloc.c
+++ b/Objects/obmalloc.c
@@ -3266,6 +3266,15 @@ py_mimalloc_print_stats(FILE *out)
static void
pymalloc_print_stats(FILE *out)
{
+ PyThreadState *tstate = _PyThreadState_GET();
+ if (tstate == NULL || tstate->interp == NULL) {
+ return;
+ }
+
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ if (interp == NULL || interp->obmalloc == NULL) {
+ return;
+ }
OMState *state = get_state();
uint i; |
Call _PyObject_DebugMallocStats() earlier in Py_FinalizeEx(), before the interpreter is deleted.
Call _PyObject_DebugMallocStats() earlier in Py_FinalizeEx(), before the interpreter is deleted.
I wrote PR gh-120021 to fix the issue. |
Call _PyObject_DebugMallocStats() earlier in Py_FinalizeEx(), before the interpreter is deleted.
Call _PyObject_DebugMallocStats() earlier in Py_FinalizeEx(), before the interpreter is deleted. (cherry picked from commit 5a1205b) Co-authored-by: Victor Stinner <[email protected]>
Call _PyObject_DebugMallocStats() earlier in Py_FinalizeEx(), before the interpreter is deleted. (cherry picked from commit 5a1205b)
…120022) gh-111499: Fix PYTHONMALLOCSTATS at Python exit (GH-120021) Call _PyObject_DebugMallocStats() earlier in Py_FinalizeEx(), before the interpreter is deleted. (cherry picked from commit 5a1205b) Co-authored-by: Victor Stinner <[email protected]>
Call _PyObject_DebugMallocStats() earlier in Py_FinalizeEx(), before the interpreter is deleted.
Call _PyObject_DebugMallocStats() earlier in Py_FinalizeEx(), before the interpreter is deleted.
Call _PyObject_DebugMallocStats() earlier in Py_FinalizeEx(), before the interpreter is deleted.
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
The text was updated successfully, but these errors were encountered: