On Jun 25, 3:28 pm, qwcode <qwc...@gmail.com> wrote:
> > So, as far as question you pose in different thread, look at Python
> > module global variables. If you don't understand how that helps, then
> > you don't understand how Python global variables work. Just be aware
> > of the issues that global variables cause in context of multiprocess
> > web server as described in documentation above.
>
> Ok, my take away is the following. please correct me if I'm wrong. I'm
> just trying to get my head around it.
>
> 1) In django, if you want "application scoped" objects, using module
> globals (similar to java static variables) is your only recourse.
> There is no parallel to Java servlet's ServletContext, or cherrypy's
> Application object

It isn't necessarily the only way, but it is the easiest and since you
cannot run multiple Django instances within the one Python (sub)
interpreter you don't get an issue of two application instances within
same process trying to access the same values.

> 2) Depending on your web server config, you may have multiple
> instances of these globals, so if you're planning on these being
> mutable, then you could have problems

If you expect the change made in one process to be reflected in all
processes, then yes it is a problem. If you are using them for per
process caching where cached information would be same even if
generated in different process, then not an issue.

> 3) If your intention is to use non-mutable, thread-safe globals, then
> you're ok under all configurations, you  just might have multiples of
> the same globals running.

If they are non mutable, is thread safety even an issue? I guess that
depends on whether you initialise the global value on module import or
not. If done at module import, then no thread locking needed. Only
need thread locking if initialisation will be performed from an actual
request handler first time it is necessary.

Graham
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to