[mod_python] mod_python session trouble

Wouter van Marle wouter at squirrel-systems.com
Tue May 10 06:33:53 EDT 2005

Update on my own message:
I have changed the structure a bit, sess has now become req.session, so
I can pass around the session together with the request object easily.
The locking problem has been solved by calling req.session.unlock()
every time after saving the session, however this causes the server to
start a new session for each request, and that's not the idea, as then
info gets lost.
Also I've noticed that writing and reading back of cookies does not work
properly. I'm trying to write a cookie, and when reading it back in case
of a new session I get the old data again. But that's for another

Any advice is highly appreciated!


On Tue, 2005-05-10 at 14:53 +0800, Wouter van Marle wrote:

> On Tue, 2005-05-10 at 02:01 -0400, Jim Gallacher wrote:
> > This looks like a problem with session locking, which is the default 
> > when creating a session. Are you creating more than one session object 
> > in a request? If so you'll end up with a deadlock. For example the 
> > following code will deadlock as it is really just accessing the same 
> > session data:
> > 
> > sess1 = Session.Session(req)
> > sess2 - Session.Session(req)
> This is really close to what I am doing. I've to shorten my code a lot
> to get it posted here, but basically this happens:
> def home(req):
>     sess = Session.Session(req)
>     if sess.is_new():
>         # get settings from cookies (using Cookie)
>     # page built up, using sess["language"] for the language setting.
>     sess.save()    
>     return apache.OK
> def english(req)
>     sess = Session.Session(req)
>     sess["language"] = "en"
>     sess.save()
>     home(req) # to redraw the main page
> And same for other languages as well.
> The page uses a little PSP to easily set some variables, no code in the
> pages. It appears to hang on the Session.Session(req) call in the
> english routine.
> The english routine is called through a hyperlink off the main page (a
> href main.py/english).
> Wouter.
> _______________________________________________
> 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/20050510/d7682875/attachment-0001.html

More information about the Mod_python mailing list