'Borg' and multiple threads.

Mike Mazur mmazur at gmail.com
Wed Jan 9 02:16:38 CET 2008


On Jan 8, 2008 7:24 AM, Tobiah <toby at tobiah.org> wrote:
> I have a class that I call Borg that starts like this:
> class Borg(dict):
>         static_state = {}
>         def __init__(self):
>                 self.__dict__ = self.static_state
> so that I can access the same data from anywhere within
> any module or function just by instantiating one.
> This is used in a cherrypy web app.  I got to thinking
> about whether there would be confusion when multiple
> users are eventually hitting the site at the same time.
> Everything seems ok.  Each time I hit the app and examine
> the Borg() at the beginning, it seems to have no attributes.
> This is what I want.
> My question is why this seems to work.  I had the idea that
> there was a class object that is created when the file containing
> the definition is read, which actually contains the static
> information that is later accessed by instances.  Isn't this
> done when the cherrypy app first loads, rather than each time
> a browser hits the app?  Otherwise, where is the individual data
> stored for each of two simultaneous hits of the web page?

Maybe a silly question, but are you changing the values in the dict
before hitting it again and getting the empty dict?


More information about the Python-list mailing list