[mod_python] psp.PSP(req, string='hello world') causes segfault

dharana dharana at dharana.net
Tue Apr 26 18:38:09 EDT 2005


modified handler
-- -------------------------------------------------
from mod_python import apache
#from mod_python import psp

import sys
import os
import marshal
import new
from cgi import escape
import anydbm, whichdb
import tempfile

def handler(req):
#    content_file = psp.PSP(req, string='hello world')
#    content_file.run()
     return apache.OK
-----------------------------------------------------

It doesn't segfault like this.






I tried to hunt it a little bit deeper right into the mod_python's 
psp.py file:

-- site-packages/mod_python/psp.py snippet ---------------------
         if filename:

             # if filename is not absolute, default to our guess
             # of current directory
             if not os.path.isabs(filename):
                 base = os.path.split(req.filename)[0]
                 self.filename = os.path.join(base, filename)

             self.load_from_file()
         else:

             cached = mem_scache.get(string)
             if cached:
                 self.code = cached
             else:
(line 118)      self.code = _psp.parsestring(string)
                 mem_scache.store(string)
-----------------------------------------------------------------

Commenting out line 118 and trying to run the script in the previous 
email (the one that is causing the segfault) gives me this error:

--- traceback -------------------------------------------------------
Mod_python error: "PythonHandler webapps.admin.controller"

Traceback (most recent call last):

   File 
"/usr/local/hosting/lib/python2.4/site-packages/mod_python/apache.py", 
line 299, in HandlerDispatch
     result = object(req)

   File "/home/dharana/websites/ozone2/webapps/admin/controller.py", 
line 13, in handler
     content_file = psp.PSP(req, string='hello world')

   File 
"/usr/local/hosting/lib/python2.4/site-packages/mod_python/psp.py", line 
119, in __init__
     mem_scache.store(string)

TypeError: store() takes exactly 3 arguments (2 given)
-------------------------------------------------------------------

I don't know why this is failling, maybe it has something to do with the 
problem. _psp.parsestring(string) shouldn't modify "string" in any way 
nor should it be able to pass hidden args to the mem_scache.store() 
function, right?



Anyways, I tried to investigate it further but I couldn't go deeper than 
the mod_python source file src/_pspmodule.c (lines 129 to 160). My C 
skills are non-existent.






Grisha, if you read this, this is one of the previous references I found 
about the problem:

   http://www.modpython.org/pipermail/mod_python/2004-May/015552.html

Maybe the typo/bugfix didn't completely solve the problem at hand.



Graham Dumpleton wrote:
> The segmentation fault problems are generally caused by a mismatch in 
> versions
> of shared libraries that various packages have been compiled against. 
> The main
> culprits are libexpat, MySQL client libraries and sometimes Sleepycat 
> DBM. The
> clash is between the version expected by PHP or Apache, and that which 
> may be
> expected by a Python module being used. Because it is an environment 
> issue, it
> may well only affect you.

Thank you for the explanation!

-- 
dharana



More information about the Mod_python mailing list