[mod_python] global variables are not made global?

Mephisto badmephisto at gmail.com
Mon Jul 21 01:51:01 EDT 2008


i'm so embarrassed, i cant write python I'm sorry. I made sure that I knew
how to do imports before I emailed here, but actually when i tried it i did
it just like you, with main.a and import main. However in my actual code for
mod_python I do from main import *, and then i tried to refer to a, just
normally without any prefix like in main.a. And it turns out that you cant
do that, it won't work. Sorry about that. Thank you very much for your help.

On Sun, Jul 20, 2008 at 10:44 PM, Graham Dumpleton <
graham.dumpleton at gmail.com> wrote:

> I assume that in the second file you are at least doing:
>
>  import main
>
> and then referencing 'a' as 'main.a' in the code.
>
> I was assuming that you were getting this most fundamental concept of
> Python correct.
>
> You should really post a complete (but small) example of real code
> that shows your problem.
>
> Graham
>
> 2008/7/21 Mephisto <badmephisto at gmail.com>:
> > Hi, thank you fro your reply. I should have been a little clearer. I am
> > running Windows XP and the entire code is processed within one single
> > request, so I don't see how the problems with different interpreters
> should
> > affect me. Is there something else that I could try?
> >
> > On Sun, Jul 20, 2008 at 9:54 PM, Graham Dumpleton
> > <graham.dumpleton at gmail.com> wrote:
> >>
> >> 2008/7/21 Mephisto <badmephisto at gmail.com>:
> >> > Hi, I have been trying to fix this for a while, but I cant seem to do
> >> > it:
> >> >
> >> > essentially this is my code:
> >> >
> >> > in my main .py file that handles requests:
> >> > from otherfile import othermethod
> >> > def handler():
> >> > global a
> >> > a=5
> >> > othermethod()
> >> >
> >> > in otherfile:
> >> > def othermethod()
> >> >    #in this method, the value of a is not defined, even though i made
> it
> >> > global!
> >> >
> >> > even though it says in the documentation that global data is normally
> >> > retained and handled. And all of the previous code runs within the
> same
> >> > request... am i doing something wrong? or not doing something?
> >> > thank you
> >>
> >> Read:
> >>
> >>
> >>
> http://www.dscpl.com.au/wiki/ModPython/Articles/TheProcessInterpreterModel
> >>
> >> Apache is a multiprocess web server (except on Windows), thus
> >> subsequent requests will not necessarily be handled by the same
> >> process.
> >>
> >> It is not clear from your example whether you are talking about data
> >> persisting across requests, or whether you are talking about data seen
> >> by other modules imported as part of same request.
> >>
> >> BTW, relying on globals is also dangerous for configurations where
> >> Apache is running multithreaded.
> >>
> >> That document summaries issues about global data and persistence at the
> >> end.
> >>
> >> Graham
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20080721/0281dd00/attachment-0001.html


More information about the Mod_python mailing list