[mod_python] Session Freezing using mod_python.Session

Graham Dumpleton graham.dumpleton at gmail.com
Wed Mar 14 17:24:43 EST 2007


On 15/03/07, Kenneth Loafman <kenneth at loafman.com> wrote:
> Hi,
>
> The small snippet of code below freezes if there is an existing pysid
> cookie (sample straight out of the manual).  If there is no pysid
> cookie, then index() displays, but show() hangs.

Yet you don't show us the code in show() which is the important bit.

Does show() call any other functions in which you are trying to create
a Session object a  subsequent time. If you are it will hang as you
can create only one Session object instance per request. In other
words, if show() was for example written as:

  def show(req):
      session = Session.Session(req)
      return index(req)

you would have this problem with it hanging as show already has a lock
on the session

Normal practice is to always use:

     if not hasattr(req,'session'):
       req.session = Session.Session(req)

     if req.session.is_new():
       ...

Thus, always check to see if req.session has been already set by
something else and only create a new Session object if it hasn't,
assigning it to req.session and always using it from there as well.

If this doesn't help, post the code for show() and what it may call.

Graham

> Platform is Ubuntu Edgy 64-bit, Apache, mod_python, python 2.4.
>
> Any suggestions would be appreciated.
>
> ...Thanks,
> ...Ken
>
> def index(req):
>     session = Session.Session(req)
>     if session.is_new():
>        session['hits'] = 1
>     else:
>        session['hits'] += 1
>     session.save()
>     return """\
> %s
> <fieldset>
> <legend>
> Please select the database:
> </legend>
> <form method="post" action="/demo/index/show">
> <...snip...>
> %s
> """ % (_head, _tail)
>
> def show(req):
>     session = Session.Session(req)
>     <...snip...>
> _______________________________________________
> 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