[mod_python] Session Pickling Error II - 3.2.2b

Nicolas Lehuen nicolas.lehuen at gmail.com
Tue Oct 4 01:40:36 EDT 2005


As explained in the error message, function objects can't be pickled. This
is not a mod_python limitation, rather a Python limitation.

There are three workarounds I can think of :

1) If you are using the threaded MPM (but I think you're not), use
MemorySession instead of DBMSession or FileSession. This way, session are
never pickled. The disadvantage is that all sessions are lost as soon as
Apache is restarted, since sessions are stored in RAM and not on disk.

2) Do not store any function object in the session and implement a
workaround by yourself, i.e. try to store a pickable value from which you
can infer the function. This means that you must forget about directly
storing functions in the session and having a kind of naming system (store
the name of the function in the session and fetch the function according to
its name).

3) Customize the pickling / unpickling of the objects you want to store in
the session, using __getstate__ and __setstate__ (see the Python


2005/10/4, GATOR AIDE <gator_aide2000 at yahoo.com>:
> After updating mod_python 3.1.4 to 3.2.2b I am getting
> an error:
> PythonHandler mod_python.publisher: TypeError: can't
> pickle function objects
> I am storing a function in the session and calling
> session.save(). (Which is when the error is raised.)
> Using mod_python 3.1.4 the code works just fine but
> after the update I am now seeing this error.
> The code simply stores a dictionary and few function
> callbacks in the session and loops through several
> functions until it is done processing.
> Not sure if anyone else has had this problem? I
> running centos 2.4.21-27.0.4.ELsmp on a x86_64
> platform. Python 2.4.2 (same error w/2.4.1). Apache
> 2.0.46.
> I wasn't sure if this is the right place to post this,
> so I apologize if I should have posted the question
> elsewhere.
> Thanks,
> Mike
> __________________________________
> Yahoo! Mail - PC Magazine Editors' Choice 2005
> http://mail.yahoo.com
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20051004/3dac7fc5/attachment.html

More information about the Mod_python mailing list