This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author grahamd
Recipients grahamd
Date 2009-07-21.11:19:27
SpamBayes Score 4.0993414e-10
Marked as misclassified No
Message-id <1248175169.79.0.15962102552.issue6531@psf.upfronthosting.co.za>
In-reply-to
Content
I am seeing a crash within Py_Finalize() with Python 3.0 in mod_wsgi. It looks like the 
patches for issue-4200 were not adequate and that this wasn't picked up at the time.

This new problem I am seeing looks like it may be linked to where the 'atexit' module is 
initialised/imported in a sub interpreter but never imported in the main interpreter. I can 
avoid the crash by having:

    PyImport_ImportModule("atexit");

    Py_Finalize();

At a guess, the problem is because in atexit_callfuncs():

    module = PyState_FindModule(&atexitmodule);
    if (module == NULL)
        return;

still returns a module for case where imported in a sub interpreter but not in main 
interpreter, so doesn't return, but then code which follows:

    modstate = GET_ATEXIT_STATE(module);

    if (modstate->ncallbacks == 0)
        return;

returns NULL for modstate for the main interpreter as PyInit_atexit() had never been called 
for the main interpreter as the 'atexit' module was never imported within that interpreter.

The fix would appear to be to check modstate for being NULL and return. Ie.,

    module = PyState_FindModule(&atexitmodule);
    if (module == NULL)
        return;
    modstate = GET_ATEXIT_STATE(module);

    if (modstate == NULL)
        return;

    if (modstate->ncallbacks == 0)
        return;

The only thing I am uncertain about is why PyState_FindModule() would return an object. I 
cant find any documentation about that function so not entirely sure what it is meant to do. 
I would have thought it would be returning data specific to the interpreter, but if never 
imported in that interpreter, why would there still be an object recorded.

BTW, I have marked this as for Python 3.1 as well, but haven't tested it on that. The code in 
'atexit' module doesn't appear to have changed though so assuming it will die there as well.

For now am using the workaround in mod_wsgi.
History
Date User Action Args
2009-07-21 11:19:29grahamdsetrecipients: + grahamd
2009-07-21 11:19:29grahamdsetmessageid: <1248175169.79.0.15962102552.issue6531@psf.upfronthosting.co.za>
2009-07-21 11:19:28grahamdlinkissue6531 messages
2009-07-21 11:19:27grahamdcreate