[mod_python] global variables are not made global?

Graham Dumpleton graham.dumpleton at gmail.com
Sun Jul 20 22:44:43 EDT 2008


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
>
>


More information about the Mod_python mailing list