[mod_python] pass variables between functions.

donnie jones donniejones18 at gmail.com
Fri Feb 11 14:13:09 EST 2005


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.
> >
> > __
> > Donnie
> >
> >
> > On Fri, 11 Feb 2005 10:58:51 -0800, Scott Sanders <sanders at apache.org> wrote:
> >
> >>It won't work for everyone, if someone's config uses a threaded MPM for
> >>Apache, or multiple python interpreters.  Then the x global var is only
> >>global to a particular interpreter.
> >>
> >>Scott
> >>
> >>On Feb 11, 2005, at 10:49 AM, Chris Jackson wrote:
> >>
> >>
> >>>[+ mod_python]
> >>>
> >>>I've tested your code.  It works fine the way you have it (add an
> >>>output statement to def test)....
> >>>
> >>>Everytime http://path/to/your/site/test is called, x is reset to 1
> >>>Each time http://path/to/your/site/add is called, x is incremented.
> >>>
> >>>~= Chris =~
> >>>
> >>>On Fri, 11 Feb 2005 13:28:15 -0500, donnie jones
> >>><donniejones18 at gmail.com> wrote:
> >>>
> >>>>I meant retain a value across function, not constants.
> >>>>The global did not work for me..
> >>>>
> >>>>Must I "return" the variable in order for it to be
> >>>>changed for the second function?
> >>>>
> >>>>What kind of sessions issue could be happening?
> >>>>I don't have any sessions declared....
> >>>>
> >>>>Thanks.
> >>>>__
> >>>>Donnie
> >>>>
> >>>>
> >>>>On Fri, 11 Feb 2005 13:25:14 -0500, Chris Jackson
> >>>><christopher.jackson at gmail.com> wrote:
> >>>>
> >>>>>If you're looking for setting something like constants, then one
> >>>>>suggestion would be to create a separate config module of a sort :
> >>>>>
> >>>>># config.py
> >>>>>COLOR='blue'
> >>>>>SIZE=10
> >>>>>
> >>>>>Then, in your publisher handler file you can import the config module
> >>>>>and call it like so:
> >>>>>
> >>>>>from mod_python import apache
> >>>>>import config
> >>>>>
> >>>>>def test(req):
> >>>>> mycolor = config.COLOR + 1
> >>>>> mysize = config.SIZE +1
> >>>>>
> >>>>>def add(req):
> >>>>> mycolor = config.COLOR +2
> >>>>> mysize = config.SIZE + 2
> >>>>>
> >>>>>However, if by consistency, you mean retain a value across functions,
> >>>>>then using global should work fine.  You may just have an issue with
> >>>>>sessions.  What do  you ultimately want to accomplish?
> >>>>>
> >>>>>~= Chris =~
> >>>>>
> >>>>>
> >>>>>On Fri, 11 Feb 2005 12:48:47 -0500, donnie jones
> >>>>><donniejones18 at gmail.com> wrote:
> >>>>>
> >>>>>>Hello,
> >>>>>>
> >>>>>>I am wanting to have a variable's data between two functions, but I
> >>>>>>can't seem to find a reasonable way to do this with modpython
> >>>>>>publisher...
> >>>>>>
> >>>>>>example:
> >>>>>>
> >>>>>>x=0
> >>>>>>
> >>>>>>def test(req):
> >>>>>>  global x
> >>>>>>  x = 1
> >>>>>>
> >>>>>>def add(req):
> >>>>>>  global x
> >>>>>>  x=x+1
> >>>>>>  req.write("%d" % x)
> >>>>>>
> >>>>>>I would like for x to have a consistent value between the
> >>>>>>functions...
> >>>>>>I thought maybe doing req.x = 1 might work, but I did not have
> >>>>>>success
> >>>>>>between the functions, req would not maintain the value.
> >>>>>>
> >>>>>>Any suggestions would be great.
> >>>>>>Thank you.
> >>>>>>
> >>>>>>__
> >>>>>>Donnie
> >>>>>>_______________________________________________
> >>>>>>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
> >>
> >>
> > _______________________________________________
> > 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