[mod_python] Session Pickling Error II - 3.2.2b

Graham Dumpleton grahamd at dscpl.com.au
Tue Oct 4 01:25:58 EDT 2005

GATOR AIDE wrote ..
> 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.

I am going to hazard a guess and say that pickle probably only allows
you to pickle a function objects where the function object resides in a
module which was imported using "import", ie., lives in "sys.modules".

In mod_python 3.2, mod_python.publisher handler modules are no longer
imported using the Python "import" mechanism but are instead read in as
strings and executed against a dictionary of an empty module which does
not actually exist in sys.modules.

      def build(self, key, name, opened, entry):
            module = new.module(re_not_word.sub('_',key))
            module.__file__ = key
            exec opened in module.__dict__
            return module

The error would seem reasonable under these circumstances because if it
were pickled, it wouldn't perhaps be unable to unpickle it later as it
wouldn't know the name of a module in "sys.modules" to associate the
function reference to.

Are you sure you can't use a string reference or something else as a handle
to refer to the callback function rather than an actual function object?


More information about the Mod_python mailing list