[jira] Updated: (MODPYTHON-77) The multiple interpreter concept of mod_python is broken for Python extension modules since Python 2.3

2005-10-14 Thread Graham Dumpleton (JIRA)
 [ http://issues.apache.org/jira/browse/MODPYTHON-77?page=all ]

Graham Dumpleton updated MODPYTHON-77:
--

Attachment: gilstate.tar.gz

Here is my own simplified test case for the GIL state API issue which exhibits 
the problem in a different way. In this case it is where the exception:

  file() constructor not accessible in restricted mode

is raised.

Have constructed this test case as this particular problem has come up numerous 
times before. It is known that in some cases the problem is due to an actual 
error in Python (when Python 2.3.5 or later is used), ie.:

  
http://sourceforge.net/tracker/index.php?func=detail&aid=1163563&group_id=5470&atid=105470

The attached test case causes a problem though when using Python on Mac OS X 
(10.3) which is supposed to be Python 2.3.0, thus cannot be related to the bug 
in Python and is more likely to be the GIL state API issue.

In respect of the changes already posted here now that I have started looking 
at it, what I don't understand is why the mod_python.c file has to use the GIL 
state API functions at all. I would have thought that it was enough to save the 
initial interpreter as "main_interpreter" and for users to ensure they then 
explicitly named the interpreter they used as being "main_interpreter".

Can someone please explain the reason why there has to be this special case 
processing whereby GIL state API is only used when making calls into the 
main_interpreter. This doesn't make sense, the full API for acquiring the 
thread lock as it existed should have been sufficient. The only thing that 
might make sense is if it is done this way as a workaround for the bug in 
Python listed above on SourceForge.




> The multiple interpreter concept of mod_python is broken for Python extension 
> modules since Python 2.3
> --
>
>  Key: MODPYTHON-77
>  URL: http://issues.apache.org/jira/browse/MODPYTHON-77
>  Project: mod_python
> Type: Bug
>   Components: core
> Versions: 3.1.4
>  Environment: Python >= 2.3
> Reporter: Boyan Boyadjiev
>  Attachments: diff.txt, diff2.txt, diff3.txt, gil_test.c, gilstate.tar.gz, 
> mod_python.c, mod_python.c.diff, mod_python.h.diff, src.zip
>
> The multiple interpreter concept of mod_python is broken for Python extension 
> modules since Python 2.3 because of the PEP 311 (Simplified Global 
> Interpreter Lock Acquisition for Extensions):
> ...
> Limitations and Exclusions
> This proposal identifies a solution for extension authors with
> complex multi-threaded requirements, but that only require a
> single "PyInterpreterState".  There is no attempt to cater for
> extensions that require multiple interpreter states.  At the time
> of writing, no extension has been identified that requires
> multiple PyInterpreterStates, and indeed it is not clear if that
> facility works correctly in Python itself.
> ...
> For mod_python this means, that complex Python extensions won't work any more 
> with Python >= 2.3, because they are supposed to work only with the first 
> interpreter state initialized for the current process (a problem we 
> experienced). The first interpreter state is not used by mod_python after the 
> python_init is called. 
> One solution, which works fine for me, is to save the first interpreter state 
> into the "interpreters" dictionary in the function python_init 
> (MAIN_INTERPRETER is used as a key):
> static int python_init(apr_pool_t *p, apr_pool_t *ptemp,
>apr_pool_t *plog, server_rec *s)
> {
> ...
> /* initialize global Python interpreter if necessary */
> if (! Py_IsInitialized())
> {
> /* initialze the interpreter */
> Py_Initialize();
> #ifdef WITH_THREAD
> /* create and acquire the interpreter lock */
> PyEval_InitThreads();
> #endif
> /* create the obCallBack dictionary */
> interpreters = PyDict_New();
> if (! interpreters) {
> ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, s,
>  "python_init: PyDict_New() failed! No more memory?");
> exit(1);
> }
> {   
> /*
> Workaround PEP 311 - Simplified Global Interpreter Lock 
> Acquisition for Extensions
> BEGIN
> */
> PyObject *p = 0;
> interpreterdata * idata = (interpreterdata 
> *)malloc(sizeof(interpreterdata));
> PyThreadState* currentThreadState = PyThreadState_Get();
> PyInterpreterState *istate = currentThreadState->interp;
> idata->istate = istate;
> /* obcallback will be created on first use */
> idata->obcallback = NULL;
> p = PyCObject_FromVoidPtr((void ) idata, NULL); /*p->refcout = 1*/
> PyDict_SetItemString(interpreters

[jira] Created: (MODPYTHON-82) mod_python.publisher cache will not work if threading not built into Python

2005-10-14 Thread Graham Dumpleton (JIRA)
mod_python.publisher cache will not work if threading not built into Python
---

 Key: MODPYTHON-82
 URL: http://issues.apache.org/jira/browse/MODPYTHON-82
 Project: mod_python
Type: Bug
  Components: publisher  
Versions: 3.2.0
 Environment: Python --without-threads
Reporter: Graham Dumpleton


The mod_python.cache module will not work if threads are not built into Python.

Mod_python error: "PythonHandler mod_python.publisher"

Traceback (most recent call last):

  File 
"/home/grahamd/testing/lib/python2.3/site-packages/mod_python/apache.py", line 
287, in HandlerDispatch
log=debug)

  File 
"/home/grahamd/testing/lib/python2.3/site-packages/mod_python/apache.py", line 
461, in import_module
module = imp.load_module(mname, f, p, d)

  File 
"/home/grahamd/testing/lib/python2.3/site-packages/mod_python/publisher.py", 
line 50, in ?
from cache import ModuleCache, NOT_INITIALIZED

  File "/home/grahamd/testing/lib/python2.3/site-packages/mod_python/cache.py", 
line 23, in ?
from threading import Lock

  File "/home/grahamd/testing/lib/python2.3/threading.py", line 6, in ?
import thread

ImportError: No module named thread

Instead of the code:

from threading import Lock

It should use:

try:
  from threading import Lock
except:
  class Lock:
def acquire(self): pass
def release(self): pass


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira



[jira] Created: (MODPYTHON-83) mod_python doesn't work if threads not compiled into Python

2005-10-14 Thread Graham Dumpleton (JIRA)
mod_python doesn't work if threads not compiled into Python
---

 Key: MODPYTHON-83
 URL: http://issues.apache.org/jira/browse/MODPYTHON-83
 Project: mod_python
Type: Bug
  Components: core  
Versions: 3.1.4, 3.2.0
Reporter: Graham Dumpleton


If threads aren't built into Python, mod_python generates errors:

  Fatal Python error: PyThreadState_Delete: tstate is still current

when a request arrives for mod_python and crashes the Apache child subprocess.

The fix as previously described in:

  http://www.modpython.org/pipermail/mod_python/2005-October/019236.html

does appear to fix the problem on initial testing.

Testing was done on Linux with no threads builtin to Python.

This problem is probably more prevelant on FreeBSD where Python still seems to
default to not having thread support builtin.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira