[mod_python] Memory Session doesen't work withPythonInterpPerDirectory on Windows

Graham Dumpleton grahamd at dscpl.com.au
Wed Oct 18 18:10:17 EDT 2006


Luca Montecchiani wrote ..
> Hi all,
> this is probably a FAQ but I want to share with you
> my bad experience.
> 
> I've a situation where /www/dir1/login.py create a session and
> redirect to /www/dir2/desktop.py that read the session to see
> if is_new or not.
> 
> Unfortunately this doesn't work if you are using:
> 1) Windows platform
> 2) PythonOption PythonInterpPerDirectory On
> 3) PythonOption Session MemorySession
> 
> The desktop.py check if the session is new and
> it is always True :-(
> 
> This seem pretty simple to explain, having Session
> saved in Memory the second python interpreter (/www/dir2) doesn't
> "see" the session created by the first interpreter (/www/dir1)
> because of the PythonInterpPerDirectory option.
> 
> Now if I want to make it work I have to turn off the
> PythonInterpPerDirectory or change the Session from
> MemorySession to DbmSession .
> Of course this will not happen if the desktop.py where
> on the same directory of the login.py script.
> 
> Is this a correct analysis ?
> If it is must be a FAQ IMHO and what is the best practice
> to avoid this problem ?

What version of mod_python are you using? There are bugs related to
PythonInterpPerDirectory in older versions, and not all problems may
even be addressed until mod_python 3.3. You should avoid using the
PythonInterpPerDirectory unless you have a very good reason.

For a possible workaround, try setting:

  PythonOption ApplicationPath /www

This will ensure that cookies used for session in each context use the
same path. They will not otherwise if you have distinct PythonHandler
directives in each context, irrespective of whether you are using the
PythonInterpPerDirectory directive.

There is also perhaps an issue in mod_python session code as well
which I hadn't noticed before. That is that it uses:

            # the path where *Handler directive was specified
            dirpath = self._req.hlist.directory 
            if dirpath:
                docroot = self._req.document_root()
                c.path = dirpath[len(docroot):]
            else:
                c.path = '/'

This will not work though where the directory the handler is specified
for is not located within the document root. There are possibly other
issues with this code in relation to mod_python 3.3 which I'll have to
address as well.

This issue is incidental though and probably not the cause of any
problem you have.

BTW, why are you using PythonInterpPerDirectory? What do you think
you get from using it?

Graham



More information about the Mod_python mailing list