[mod_python] global variables are not made global?

Graham Dumpleton graham.dumpleton at gmail.com
Sun Jul 20 21:54:29 EDT 2008

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



Apache is a multiprocess web server (except on Windows), thus
subsequent requests will not necessarily be handled by the same

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.


More information about the Mod_python mailing list