[mod_python] Hello all, Questions about Mod Python sessions on Linux

michael bayer mike_mp at zzzcomputing.com
Wed Nov 10 18:09:43 EST 2004


seems like you are trying to store a Python module in the Session, and 
Pickle isnt able to do that.

regardless of which platforms this may or may not work on, it generally 
doesn't make sense to store a module in the session, since a Python 
module and its instance variables, assuming normal usage via "import", 
are all shared amongst many requests and possibly across multiple 
concurrent threads, whereas the Session stores information specific to 
one user and that user's subset of requests.

you probably want to figure out what application state it is exactly 
you want to store on a per-session basis, and stick it into an object 
instance that you can safely pickle away.

if you are unsure what object in your Session is a module, you can 
always try walking through all the elements in the session and test 
obj.__class__.__name__ == 'module' to see who the offending element is.

On Nov 10, 2004, at 4:24 PM, Trevor West wrote:

> Setups for use in the below discussion:
> Machine 1:
> Windows 2000
> Apache 2.0.52
> Mod Python 3.1.3
> MySQL_Python
> Python 2.3
> wxPython
>
>
> Machine 2:
> Fedora Core 2
> Apache 2.0.52
> Mod Python 3.1.3
> MySQL_Python
> Python 2.3
> wxPython
>
> I'm writing a thin-client to a wxPython application and when I run the 
> thin client on Machine 1(the windows box) everything works great, no 
> problem. While when I try to move it to what is now the production 
> box, Machine 2 (linux box), I get this error:
>
> Mod_python error: "PythonHandler mod_python.publisher"
>
> Traceback (most recent call last):
>
>  File "/usr/local/lib/python2.3/site-packages/mod_python/apache.py", 
> line 299, in HandlerDispatch
>    result = object(req)
>
>  File 
> "/usr/local/lib/python2.3/site-packages/mod_python/publisher.py", line 
> 136, in handler
>    result = util.apply_fs_data(object, req.form, req=req)
>
>  File "/usr/local/lib/python2.3/site-packages/mod_python/util.py", 
> line 361, in apply_fs_data
>    return object(**args)
>
>  File "/usr/local/apache2/htdocs/test/mptest.py", line 42, in login
>    sess.save()
>
>  File "/usr/local/lib/python2.3/site-packages/mod_python/Session.py", 
> line 204, in save
>    self.do_save(dict)
>
>  File "/usr/local/lib/python2.3/site-packages/mod_python/Session.py", 
> line 329, in do_save
>    dbm[self._sid] = cPickle.dumps(dict)
>
>  File "/usr/local/lib/python2.3/copy_reg.py", line 69, in _reduce_ex
>    raise TypeError, "can't pickle %s objects" % base.__name__
>
> TypeError: can't pickle module objects
>
> So, as far as I can tell, on my Windows box I'm able to add class 
> instances to the session (in this case, I'm sure it's my database 
> class that is causing this) but on Linux, it won't add it to the 
> session.
>
> If anyone can give him a heads up that would be great. I've been 
> beating my head against the wall with the linux box because the 
> windows setup was SO easy, and being a big linux fan I was 
> disappointed in the strange problems I've run into.
>
> Anyway, thanks in advance.
>
> Trevor West
> ------------------------
> Developer for QA Labs
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python


More information about the Mod_python mailing list