[mod_python] smarter session (un)locking possible?

Andreas Klauer Andreas.Klauer at metamorpher.de
Sun Oct 15 18:23:27 EDT 2006


Hi,

I just wasted half day to get rid of a problem, which I, due to lack 
of experience, have to describe as 'random mod_python lockups'. 
Turns out they were caused because I was using Sessions, and Sessions 
lock until the end of the request by default.

The 'lockup' occurs when sending concurrent requests to the server,
which happens quite frequently when users open a lot of tabs on the 
page or - worse - download a file via mod_python.

The culprit code was actually a subroutine like this:

def _get_user_id(req):
    s = Session.Session(req)
    if s.is_new():
        s['id'] = _generate_unique_id()
    s.save()
    return s['id']

Now, first of all I don't want to complain about locking here. 
The fact that I noticed it so late, checked everywhere but there 
for a problem, just shows how much I know about locking issues. 
So it's a good thing that it is taken care of by mod_python.

However, I wonder if mod_python could not have handled this case 
in a smarter way. After all, the session is only used in a separate 
subroutine. The session object does not even exist anymore after 
it returns. Yet it may still take quite some time until the request 
completes.

If it is possible in Python when an object has no more references 
(I'm new to Python so I'm not sure), I would prefer if it could 
unlock the Session immediately. It would be safer than letting me 
doing the locking myself, because I could accidentally unlock at 
a time where it is not safe (because the reference to the session 
object is still around and could be accessed).

Regards
Andreas Klauer


More information about the Mod_python mailing list