[mod_python] Mod_python & cPickle / saving Instances

Graham Dumpleton graham.dumpleton at gmail.com
Tue Apr 1 18:08:54 EDT 2008

On 01/04/2008, Dominique.Holzwarth at ch.delarue.com
<Dominique.Holzwarth at ch.delarue.com> wrote:
> >  Pickle would work tho, if I add my own modules to the PYTHONPATH (sys.modules thingy) so that they are loaded by the standard python module loader? Is that correct?
>  Correct. Those in normal Python modules picked up from sys.path can be used.
>  In general though recommend only using basic Python types, dictionaries, lists etc. This is though just to avoid potential for problem, not that there is still a problem. Just make sure stuff you want to pickle is in modules on sys.path.
>  >  However, using the standard python module loader for own modules will cause some mod_python problems as stated in http://www.dscpl.com.au/wiki/ModPython/Articles/ModuleImportingIsBroken ?
>  Which things in particular are you talking about? The problems in that document refer to pre mod_python 3.3.1. I can't think of any specific issues with use of standard modules that would cause a problem for you in mod_python 3.3.1.
> --> I didn't mean standard python modules. I meant my _own_ modules and was talking about what effects it has when I add them to sys.path so that the 'standard python module loader' will do the import, rather than the mod_python 'loader'.
>  The thing is: As I understood it, if I just add my own modules to the sys.path they will be imported by 'standard python' (other than 'mod_python') and thus pickling would work. However, with the new mod_python import mechanism, my own modules shouldn't be added to sys.path as this mixing of paths could cause problems to mod_python or so...
>  At least that's what I have read in: http://www.modpython.org/pipermail/mod_python/2006-November/022726.html (and in there, you posted the above article :-))

No, you misunderstand. You can quite happily add additional
directories to sys.path using PythonPath directory, with those
directories holding your own modules. Alternatively, install your
modules in site wide site-packages directive. What any warning would
have been about is not adding any directories which fall into your
document tree, or which you have added to mod_python.importer.path to
sys.path. That is, the set of directories in each shouldn't overlap
otherwise you have the possibility of dual import copies.


More information about the Mod_python mailing list