[mod_python] pass variables between functions.

donnie jones donniejones18 at gmail.com
Fri Feb 11 15:39:16 EST 2005


Thank you very much for the example.
I'll definitely try it out soon.

__
Donnie


On Fri, 11 Feb 2005 15:36:12 -0500, Chris Jackson
<christopher.jackson at gmail.com> wrote:
> Use the session variable, which serializes the data in /tmp/mp_*.
> 
> Here's what you do (or what i did to make it work).
> 
> # Create a new session based on sessid passed through the form in a hidden field
> def myhandler(req, sessid=""):
>   ...
>   sess = Session(req, sessid, None, 36000, 0)  #change sessid for None
> if it's a first-time user
>   sess.load()
>   sess['mydict'] = <some value>
>   .....
>    sess.save()
> 
>    myTemplate = psp.PSP(req, filename='test.html')
>    myTemplate = run(vars = {'sessid':sessid})
> 
> #Now in your html template (PSP) file (test.html)
> <html>
> .....
> <input type="hidden" name="sessid" value="<%=sessid%>">
> .....
> </html>
> 
> So what you're doing is passing around the sessid to hidden form fields.
> And you get a different sessid for each client connection.
> 
> Issue a ( watch -d 'cat /tmp/mp_sess.dbm.dir' ) command to view new
> sessid being created (not at each page, but at each new client
> connection.
> 
> ~= Chris =~
> 
> On Fri, 11 Feb 2005 14:55:11 -0500, donnie jones
> <donniejones18 at gmail.com> wrote:
> > I assume that it would be necessary to pass the session id
> > through a url or value in a form and then use that session id
> > to retrieve the session...
> >
> > I wonder performance wise if it would be better to use the
> > session or an external database...hmm.
> >
> > Thanks.
> > __
> > Donnie
> >
> >
> > On Fri, 11 Feb 2005 13:41:14 -0600, Nick <nick at dd.revealed.net> wrote:
> > > Well, essentially that *is* an external database.  I haven't used the one
> > > that comes with mod_python, but is it possible for all requests to use the
> > > same session ID so that they all see the same session, rather than one for
> > > each client?
> > >
> > > Nick
> > >
> > > donnie jones wrote:
> > > > Ack... heh, I'd rather not go for that.  ;-)
> > > >
> > > > I wonder if I could store the variable in a session?
> > > > In my actual application, the variable is a dictionary, do you think
> > > > it would be
> > > > fine to store a dictionary inside a session's dictionary?
> > > >
> > > > Thanks for everyone's help.
> > > > __
> > > > Donnie
> > > >
> > > >
> > > > On Fri, 11 Feb 2005 13:10:21 -0600, Nick <nick at dd.revealed.net> wrote:
> > > >
> > > >>I think your only recourse here is to lower the children to 1 and up the
> > > >>number of threads (a la windows), or else use an external database to store
> > > >>your variables.
> > > >>
> > > >>Nick
> > > >>
> > > >>donnie jones wrote:
> > > >>
> > > >>>---------- Forwarded message ----------
> > > >>>From: donnie jones <donniejones18 at gmail.com>
> > > >>>Date: Fri, 11 Feb 2005 14:02:48 -0500
> > > >>>Subject: Re: [mod_python] pass variables between functions.
> > > >>>To: Scott Sanders <sanders at apache.org>
> > > >>>
> > > >>>
> > > >>>I believe I am having this problem because if I reload the x=x+1
> > > >>>function many times, sometimes it will increment the value and
> > > >>>sometimes it won't... so I assume it is depending upon which thread
> > > >>>has loaded.
> > > >>>
> > > >>>Is there a way around this so that I have a consistent value between
> > > >>>the functions?
> > > >>>
> > > >>>Thank you.
> > > _______________________________________________
> > > Mod_python mailing list
> > > Mod_python at modpython.org
> > > http://mailman.modpython.org/mailman/listinfo/mod_python
> > >
> > _______________________________________________
> > 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