[Python-3000] PySys_SetObject() crashes in secondary sub interpreters.

Graham Dumpleton Graham.Dumpleton at gmail.com
Fri Sep 19 13:37:09 CEST 2008


For early Python 3.0 alpha versions I had mod_wsgi working no
problems. When I tried b3 it breaks for secondary sub interpreters. In
particular, a call to PySys_SetObject() crashes.

>From what I can tell so far the problem is that 'interp->sysdict' is
NULL after calling Py_NewInterpreter() to create a secondary sub
interpreter.

Reading through code and using a debugger, at this point this seems to
be due to condition if code:

        sysmod = _PyImport_FindExtension("sys", "sys");
        if (bimod != NULL && sysmod != NULL) {
                interp->sysdict = PyModule_GetDict(sysmod);
                if (interp->sysdict == NULL)
                        goto handle_error;
                Py_INCREF(interp->sysdict);
                PySys_SetPath(Py_GetPath());
                PyDict_SetItemString(interp->sysdict, "modules",
                                     interp->modules);
                _PyImportHooks_Init();
                initmain();
                if (!Py_NoSiteFlag)
                        initsite();
        }

in Py_NewInterpreter() not executing due to
_PyImport_FindExtension("sys", "sys") returning NULL.

Down in _PyImport_FindExtension(), it appears that the reason it fails
is because of following returning with NULL.

        def = (PyModuleDef*)PyDict_GetItemString(extensions,
filename);

        .....

                if (def->m_base.m_init == NULL)
                        return NULL;

In other words, whatever m_base.m_init is meant to be is NULL when
perhaps it isn't meant to be.

(gdb) call ((PyModuleDef*)PyDict_GetItemString(extensions,"builtins"))-
>m_base.m_init
$9 = (PyObject *(*)()) 0
(gdb) call ((PyModuleDef*)PyDict_GetItemString(extensions,"sys"))-
>m_base.m_init
$10 = (PyObject *(*)()) 0

I am going to keep tracking through to try and work out why, but
posting this initial information in case this rings a bell with
anyone.

I'll also try creating a small test outside of mod_wsgi which creates
a secondary interpreter and calls PySys_SetObject() to see if it
crashes. This should show if there is an underlying problem, or
something to do with how mod_wsgi uses interpreter creation code.

Thanks in advance for any feedback.

Graham


More information about the Python-3000 mailing list