[mod_python] Cookies and sessions trouble

Graham Dumpleton grahamd at dscpl.com.au
Thu May 12 23:24:53 EDT 2005


Wouter van Marle wrote ..
> Sometimes I feel so stupid... remembering "no req.write before finishing
> the cookies", Stripping those, the cookies part at least works within
> this test module, and seems to work OK in the real page as well. Now the
> rest of the problems still persist:
> 
> main.py/home produces a page that a.o. links to user.py/register.
> 
> user.py imports main.py (import main), and sometimes gets the error
> message "No module named main". Sometimes it goes fine, and the module
> is imported and starts running.
> 
> It seems the include goes well, as long as I to it within a minute or
> two from loading the home page (main.py/home). If quickly after that I
> click <reload> in the browser it goes fine, a moment later I get the
> include error.
> 
> Also I just noticed that changes made to main.py are not used when
> including main in user.py, until I restart apache. I got some old
> wordings that were changed in the source. Some too persistent caching at
> work here?


Using "import main" is not a good idea when the "main.py" is also being
loaded by mod_python by its module loading system. Instead of:

  import main

use:

  main = apache.import_module("main")

You may have to use something like:

  import os

  directory = os.path.split(__file__)[0]
  main = apache.import_module("main",path=[directory])

if wanting to load a module from a location not in sys.path. The latter is
in some ways perfered so as to make sure you get the correct version.

Hmmm, this all may not work in mod_python 3.2 from what I have
seen of changes to module loading mechanism used specifically for
mod_python.publisher in that version. You may have to replace use of
apache.import_module() with use of publisher specific module loader
in that version when it is available.

Graham


More information about the Mod_python mailing list