[Web-SIG] Global Variables

Shannon -jj Behrens jjinux at gmail.com
Sat Sep 10 18:36:10 CEST 2005

I second the statement about multi-threading headaches if you use
globals in this way.

In Aquarium, since I have to support different threading API's (no
threads, Python threads, coroutines), I put everything in a Context
object, and then pass that Context object to everything's constructor.
 This isn't as bad as it sounds.  It happens automatically when I call
aquariumFactory(moduleName, *args, **kargs) which does a dynamic
import, instantiates the class passing the Context object and the
additional args, and then returns the instance.

Best Regards,

On 9/9/05, Robert Brewer <fumanchu at amor.org> wrote:
> 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
> _______________________________________________
> Web-SIG mailing list
> Web-SIG at python.org
> Web SIG: http://www.python.org/sigs/web-sig
> Unsubscribe: http://mail.python.org/mailman/options/web-sig/jjinux%40gmail.com

I have decided to switch to Gmail, but messages to my Yahoo account will
still get through.

More information about the Web-SIG mailing list