[mod_python] session locking causes hang with mpservlets

Daniel Popowich dpopowich at comcast.net
Mon Mar 28 09:38:19 EST 2005

Graham Dumpleton writes:
> On 28/03/2005, at 10:31 AM, Graham Dumpleton wrote:
> > The change in mpservlets is:
> >
> >     def __cleanup_session(self):
> >         if self.use_session and self.session is not None:
> >             self.session.save()
> >             self.session.unlock()
> >             self.session = None
> >
> > Ie., add call to unlock() just after saving the session.
> >
> > Normally this unlock() would be called, but only when the Session
> > object itself is deleted or by way of a cleanup function
> > registered against the request using req.register_cleanup().
> >
> > The problem is that even though one sets self.session to None,
> > this doesn't mean it will be deleted immediately as one is in part
> > at the mercy of the Python garbage collector. That it isn't
> > unlocked may actually keep it alive longer and normally it may
> > only be unlocked by request cleanup function at which point it
> > then gets destroyed.

Thanks for digging into this Graham.  Yes, I thought this would be

            self.session = None

as the garbage collector would clean up the session.  I have used this
extensively with and without internal redirects, without error or
deadlock, but as you say, you're at the whimsy of the garbage

To be on the safe side, I will patch mpservlets to include the explict
call to unlock().

Daniel Popowich

More information about the Mod_python mailing list