[mod_python] Session instances can't be stored in req?

Gregory (Grisha) Trubetskoy grisha at modpython.org
Tue Jan 13 22:26:29 EST 2004


Technically speaking the server doesn't hang, but your particular session
does.

The Session object contains a reference to a request object, and when you
assign a session to a request you get a circular reference, therefore, the
session unlock() method is never called.

I have patched up mod_python so that now whenever the Session.lock() is
called, it will register a cleanup to always unlock at the end of the
request.

This should address the hang, but I suspect that such a circular reference
may end up eating memory, so it's probably a good idea to explicitely
delete the [in this case] req.blupp attribute after you no longer need it
with something like:

req.blupp = None

Grisha

On Fri, 7 Nov 2003, Stian [iso-8859-1] S?iland wrote:

> Again with 3.1.2b..
>
> I've gone a bit tired of creating the session objects on every page, so
> I made a fixuphandler to do the trick. The problem is, Apache hangs for
> infinity:
>
> def fixuphandler(req):
>     # req.session = Session(req)
>     sezz = Session(req)
>     req.blapp = str(id(sezz))
>     req.blupp = sezz
>     open("/tmp/faentosk", "w")
>     return apache.OK
>
>
> Within index.py:  (result is a html document)
>
> try:
>     result.add(req.blapp)
>     result.add(str(id(req.blupp)))
>     result.add(str(req.sezz))
> except Exception, e:
>     result.add(str(e))
>
> Now, if I don't save the session instance (the sezz) - everything works. If I
> try to store sezz in req.blupp - everything fails - the apache process hangs,
> the file /tmp/faentosk is never created, ie. everything stops at the
> previous line.
>
> I've tried making a Dummy class and instanciating it instead, sezz =
> Dummy() - and writing out the id in same way, works like a charm, and
> the id confirms that it's the same object instanciated within
> fixuphandler.
>
> Any tip?
>
> --
> Stian S?iland               Work toward win-win situation. Win-lose
> Trondheim, Norway           is where you win and the other lose.
> http://www.soiland.no/      Lose-lose and lose-win are left as an
>                             exercise to the reader.  [Limoncelli/Hogan]
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>


More information about the Mod_python mailing list