Instantiating only one object of a Product in Zope 2.5.1

Terry Hancock hancock at
Tue Jan 7 04:23:34 CET 2003

sameer wrote:
> I have a product that I wrote in zope which is just a big hash.  It
> loads in company names as keys, and from a text file, adds ticker
> items as each value for a particular key.  Now I only want this huge
> dictionary to load once, which is when zope starts up (possibly in a
> global space), as I need one copy of it and I need that one copy to
> update every x number of minutes.  Currently, I think, each user that
> views this product, loads his own copy of the hash, which makes it
> slow and a memory hog.  I only want a single copy available to all
> users, and the data refresh time to be determined by the system or the
> user.

As with most problems, there's more than one solution.  Given your problem, 
I would probably avoid using a dictionary and just put the information in a 
MySQL database. But there's overhead involved in setting that up, so you 
might not want to.

The key question is when and how often does the data in this dictionary 

You might want to consider making this dictionary a global module variable, 
and accessing it from the product object, rather than storing it as an 
attribute of the object (which sounds like what you're doing now). Then you 
just make a method to retrieve this data instead of storing it directly.

If the data is being filled in from a file on the filesystem (not a zope 
object), and need not use Zope's persistence mechanism, this may be the 
right answer.

But it's hard to say without more details, and you'll probably get more 
specific information from the Zope mailing list, as has already been 


Anansi Spaceworks

More information about the Python-list mailing list