Subclassing from Custom Python Classes
I need some guidance or pointers to more information. My Zope journey began last Thursday and I've been glued to zope.org ever since. I'm trying to understand the following paragraph from the Zope Developer's Guide from the section on "Subclassing from Custom Python Classes":
You should also note that your subclass must obey the ZODB persistence rules, which basically state that mutable sub-objects should be treated immutably. For example,
self.bird='parrot' # OK self.map['bird']='parrot' # NOT OK, will not trigger persistence machinery m=self.map m['bird']='parrot' self.map=m # OK, treats a mutable object immutably
What are these "persistence rules" and how come the second example is ok? I thought in Python, when you assign "m = self.map" that m is simply pointing to the same object as self.map and that any changes to m affect self.map too? Does the "self.map = m" have any effect? Don't they point to the same object? I ask because I've already built my first product based on a custom python class I wrote (its a router object that has methods to query various snmp oids) based on a ZClass and I want to make sure that I am not doing anything wrong. In addition to the methods that query the oids, I store the results in an instance variable of my Python class so I can cache the information for a specified amount of time. Is this safe to do? Can I store these values in my Python instance (self.xxxx), not a ZClass property? Also, What happens if multiple people activate my query method, do I need to worry about them stomping over each other as the method writes the results to the instance variables? Is there any record locking of objects? Lastly, since I couldn't really find any pointers regarding a builtin Zope scheduler that is bug free, I need to write a small python script that I can place in a cron job to run every ten minutes to call the query methods of these objects so they update their cache instances. Is there a link on how to get a regular Python script access to the ZODB? Thanks in advance!! Zope is great!! Pete -- Peter Kazmier http://www.kazmier.com PGP Fingerprint 4FE7 8DA3 D0B5 9CAA 69DC 7243 1855 BC2E 4B43 5654
On Tue, 23 May 2000, Pete Kazmier wrote:
Zope scheduler that is bug free, I need to write a small python script that I can place in a cron job to run every ten minutes to call the query methods of these objects so they update their cache instances. Is there a link on how to get a regular Python script access to the ZODB?
Take a look at Client.py in the ZPublisher subdirectory. --RDM
participants (2)
-
Pete Kazmier -
R. David Murray