[mod_python] PSP Response

Graham Dumpleton grahamd at dscpl.com.au
Tue May 17 20:15:26 EDT 2005

Jeremy Kohansimeh wrote ..
> Hello,
> The following fragment of code will sometimes return a response and other
> times just hang:
> <code>
> def genGraphWAnnotsHTMLResponse( req, frames):
> """generates HTML response for request to graph"""
> session = req.session
> seg_facade = session.seg_facade
> column_header, data = genSegmentAnnotsHTML( frames, session.chrom_num,
> seg_facade)
> vars = { 'p_extend' : seg_facade.p_extend, \
> 'p_break' : seg_facade.p_break, \
> 'plot_image' : os.path.join( '../../images', session.original_image), \
> 'session' : session.id(), \
> 'cols' : column_header.__str__(), \
> 'data' : data.__str__() }
> return psp.PSP( req, filename=ZOOM_WANNOTS_TMPL, vars=vars)
> </code>
> The path from the handler to here appears to be working fine. I did some
> debugging and can tell that the problem is somewhere in the psp.PSP call.
> I 
> think it may have something to do with the interpreter, but that is just
> a 
> wild guess. Has anyone had similar issues?

One problem you can hit with this code, and for which there has
been a little discussion about over the last few days in the dev
area, is that the following code will hang if your PSP page tries
to reference the "session" object. The problem is that the PSP
class ignores the fact of whether or not you may have created
your own session object and will create its own if "session" is
referenced from the PSP page, with the session object it thus
creates being stored as "session" with the execution environment
of PSP so as to be accessible from your page.

Now you actually set "session" in your vars to the session ID
which if you try to access in the page will trigger the creation
of the second session object, although your session ID setting
will override PSPs attempt to set "session" to the session object
it creates. Either way, the attempt to create a second session
object for the same request can result in a deadlock.

I would suggest you try not using the "session" variable in
your vars, but use "my_session_id" for the session ID and if
you do need access to the session object you create in
PSP, set it as the "my_session" variable. Ie., avoid using
"session" name as that triggers the deadlock where you have
already created the session object.

The suggestion being dicussed in dev area is that the PSP
code check for the existance of "req.session" and if it
exists and PSP page tries to access "session", that session be set
to "req.session" rather than creating a new session object.
If this change were made for future version of mod_python,
you wouldn't need to set "session" in the vars as PSP will
do it automatically for you. In your page you could then say
"session.id()" to get the session ID.

Would this explain your problems and does avoiding using
"session" variable name in vars fix the problem?


More information about the Mod_python mailing list