[mod_python] Lock problem with FileSession

Graham Dumpleton grahamd at dscpl.com.au
Tue Mar 7 04:18:39 EST 2006

On 07/03/2006, at 8:00 PM, Manera, Villiam wrote:

> On windows work fine
> On linux: RH3 EL apache 2.0.55 mod_python:  3.2.8
> from mod_python import Session
> def fileses(req):
> 	#sess =  Session.FileSession(req)
> 	sess =  Session.DbmSession(req)
> #	sess.unlock()
> 	return fileses1(req)
> def fileses1(req):
> 	#sess =  Session.FileSession(req)
> 	sess =  Session.DbmSession(req)
> 	return 'due'
> With DbmSession again work fine
> With FileSession and without sess.unlock() fileses1 hang

Without the unlock(), they both should probably hang.

The basic rule with sessions is that you should only create one per  
This is because the first will grab a lock on the session, creating a  
will cause the thread to deadlock on itself as it waits for the first  
session to
be unlocked.

You should use code like the following:

         if not hasattr(req,"session"):
             req.session = Session.DbmSession(req)
         return req.session

def fileses(req):
        sess = _get_session(req)
	return fileses1(req)
def fileses1(req):
	sess =  _get_session(req)
	return 'due'

Ie., cache the session object in the request and use cached one if it  

Anyway, this will work in most cases, it actually needs to be more  
than this to work with internal requests and other strange cases.


More information about the Mod_python mailing list