Copterfly / modwsgi

Automatically exported from code.google.com/p/modwsgi
0 stars 0 forks source link

Python internal assertion failures when using Py_DEBUG variant of Python. #113

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When Python compiled with Py_DEBUG, mod_wsgi will fail at some point due to 
failed assertion check on Python code 
in PyThreadState_Swap(). Specifically on:

#if defined(Py_DEBUG) && defined(WITH_THREAD)
        if (newts) {
                /* This can be called from PyEval_RestoreThread(). Similar
                   to it, we need to ensure errno doesn't change.
                */
                int err = errno;
                PyThreadState *check = PyGILState_GetThisThreadState();
                if (check && check->interp == newts->interp && check != newts)
                        Py_FatalError("Invalid thread state for this thread");
                errno = err;
        }
#endif

Although not enforced when Py_DEBUG is not defined, when it is, Python is 
expecting that if main interpreter is used, 
that only simplified GIL state API is used and new thread state objects never 
created for foreign threads that execute in 
context of main interpreter.

The mod_wsgi code was already using simplified thread state API in main 
interpreter when handling requests, thus 
avoiding problems with third party C extension modules that required use of 
simplified thread state API, but mod_wsgi 
was still wrongly creating a distinct thread state for main thread when first 
initialising main interpreter with mod_wsgi 
details. This cause the assertion failure only when using Py_DEBUG, but 
otherwise didn't cause any problems.

Original issue reported on code.google.com by Graham.Dumpleton@gmail.com on 18 Oct 2008 at 3:46

GoogleCodeExporter commented 9 years ago
Fixed in revision 1092 of subversion trunk for mod_wsgi 3.0.

Original comment by Graham.Dumpleton@gmail.com on 18 Oct 2008 at 9:54

GoogleCodeExporter commented 9 years ago
Version 3.0 of mod_wsgi now released with this change. Should be totally 
compliant with Python thread API now, 
which is quite tricky.

Original comment by Graham.Dumpleton@gmail.com on 22 Nov 2009 at 2:57