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 <>
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:



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

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

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)

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)
    modstate = GET_ATEXIT_STATE(module);

    if (modstate == NULL)

    if (modstate->ncallbacks == 0)

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.
Date User Action Args
2009-07-21 11:19:29grahamdsetrecipients: + grahamd
2009-07-21 11:19:29grahamdsetmessageid: <>
2009-07-21 11:19:28grahamdlinkissue6531 messages
2009-07-21 11:19:27grahamdcreate