[issue38997] test__xxsubinterpreters test_atexit test_capi test_threading are leaking references

STINNER Victor report at bugs.python.org
Sun Dec 8 16:03:30 EST 2019


STINNER Victor <vstinner at python.org> added the comment:

This reference leak is not new :-) It exists since at least Python 2.7. Extract of Python 2.7, Python/pythonrun.c:

    sysmod = _PySys_Init();
    if (sysmod == NULL)
        Py_FatalError("Py_Initialize: can't initialize sys");
    interp->sysdict = PyModule_GetDict(sysmod);

There is a missing Py_DECREF(sysmod). It was the same bug here, except that the code was deeply refactored in the meanwhile. I fixed the reference leak in commit 080ee5a88406fb68aaab741145cd5d2a7c5f2ad6.

Next question: why did the buildbot turn red? Well, at Python exit, there are like 18k references which are never decremented at Python exit:

$ ./python -X showrefcount -c pass
[18562 refs, 6494 blocks]

Previously, the subinterpreter sys module somehow shared references with the main interpreter. With my latest changes, the subinterpreter better isolates its own sys module from the main interpreter, and so the very old bug suddenyl is "releaved".

Getting subinterpreter "right" requires to fix all these very old bugs, one by one...

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38997>
_______________________________________


More information about the Python-bugs-list mailing list