[mod_python] Sessions again...

Luis M. Gonzalez luismg at gmx.net
Fri Jan 20 11:49:21 EST 2006



 Graham, Jim, thank you very much for your quick an accurate advices!



 ----- Original Message ----- 
 From: "Graham Dumpleton" <grahamd at dscpl.com.au>
 To: "Luis M. Gonzalez" <luismg at gmx.net>
 Cc: "Jim Gallacher" <jpg at jgassociates.ca>; <mod_python at modpython.org>
 Sent: Thursday, January 19, 2006 8:01 PM
 Subject: Re: [mod_python] Sessions again...


> Luis M. Gonzalez wrote ..
>> Ok, Jim, I'll clarify the problem:
>> Both scripts initiate their sessions the same way and with the same name:
>>
>> Script nr.1:
>>
>>     s= Session.Session(req)
>>     if s.is_new():
>>        s['items'] = {}
>>
>> Script nr.2:
>>
>>     s= Session.Session(req)
>>     if s.is_new():
>>        s['counter'] = 0
>>
>> I did it this way because I asume that for using both scripts in the same
>> site, I should have only one session started.
>> (Note that I also tried starting different sessions for each script, with
>> different names, but the problem persists).
>>
>> Actually, I already fixed this problem (with a wacky work-around 
>> though...).
>> In each script, I created the session variable corresponding to the other
>> script, as follows:
>>
> That is not a wacky work around, it is what must be done. For any
> scripts which are located under the same PythonHandler directive, the
> session object initialisation, ie., what is done when s.is_new() is
> true, must be the same for all scripts. If not done like this, as you
> are finding, when the other script is run it will be missing what it
> needs as it hasn't has the opportunity to do its initialisation. The
> other option as Jim pointed out is to effectively ignore s.is_new() and
> simply add a default for the value if the attribute isn't present.
>
> In general it is a good idea to separate out initialisation for a new
> session object into a separate common routine which all scripts call, if
> there are special attributes which need to be set up.
>
> Graham



More information about the Mod_python mailing list