[mod_python] mod_python sessions, locking, and PSP

Michael Spang mike at utgard.net
Sun Aug 13 13:50:27 EDT 2006

I recently ran into deadlocks using sessions in both my mod_python
handler and in psp. I've read through the thread at
http://www.modpython.org/pipermail/mod_python/2005-May/018035.html and
understand that this occurs because both my handler and PSP create their
own session instance and attempt to lock the session.

My question is: why doesn't the mod_python sessions module keep a
reference to each constructed session object and the thread that has it
locked? It should be possible for PSP to find and use the session object
created by the handler.

To work around this, you need to either:
    1. manually unlock the session, or
    2. pass the session to the PSP template in a different way (e.g., as
an attribute of the request object), or
    3. move everything that uses the session from the handler into the

None of these are particularly appealing. Support for the session
facility is a great feature in PSP, but it is hindered by its inability
to coexist with use of sessions outside of the template. It is quite
confusing when merely referencing the 'session' variable in a template
causes a deadlock. I was unaware of PSP's session support when I
encountered this problem; I had passed my handler's session object in
via the 'vars' argument of PSP.run().

More information about the Mod_python mailing list