[Web-SIG] Global Variables

Robert Brewer fumanchu at amor.org
Sat Sep 10 01:37:45 CEST 2005


Timothy Soehnlin wrote:
> I am working on an ongoing project, and recently 
> merged all the different segments of the request into a 
> single variable.  To propogate that variable,across function 
> calls, and imported modules, I had to pass it as a variable 
> to each function. As is visible, this is a very redundant, 
> and unnecessary action.  I recently discovered that I could 
> imbed the variable into __builtins__, and the variable is 
> accessible throughout the entire request process.  This seems 
> to work so far when the request is in CGI mode and when the 
> request is being handled by mod_python.  I was wondering if 
> anyone out there has dealt with this before, and knows 
> whether or not there is an issue in using __builtins__ as a 
> way of handling global variables, especially in respect to 
> the way mod_python handles the use of variables.  I have no 
> desire for the variable to be overwritten, or redefined in 
> the middle of a request.  

If you ever make your application multithreaded, that approach is going
to cause problems, as competing threads overwrite your request object's
attributes. You can do what CherryPy did, and use global threadlocal
objects instead. Or you could save yourself the headache and just use
CherryPy to develop your app. ;)


Robert Brewer
System Architect
Amor Ministries
fumanchu at amor.org 


More information about the Web-SIG mailing list