[Zope] Using __setstate__?

Terry Hancock hancock@anansispaceworks.com
Wed, 30 Jul 2003 16:30:45 -0700


Hi all,
I need to check for upgrades and plugins from existing 
instances of a web application, but the process is going to 
be fairly intensive, and I don't want it to get called too 
often.

Basically I need for it to be called any time the product 
is refreshed or Zope restarted.  This means that it should
get called on each instance whenever the source files
are (re-)interpreted and imported.

If I just put this into __setstate__, I'm afraid it will 
get called rather more frequently than that, but I'm not 
familiar enough with it to know how much of a problem 
that's likely to be.  Obviously just using the __setstate__ 
hook would be the easiest solution.

Is there a better hook to use?

If not, I had considered giving my class a class property 
based on the date, and then checking that in __setstate__
to determine if any further work should be done:

class  MyClass(...):
    import_date = DateTime()

    def __init__(self, ...):
        self.current_import_date = self.import_date

    def __setstate__(self, state):
        if self.import_date != self.current_import_date:
            pass # Actually do my update work here
            self.current_import_date = self.import_date

In the absence of a standard solution, this seems like the 
simplest approach.  Is this the way to go, or am I 
overlooking some "batteries" somewhere?

Obviously the idea is to allow my instances to take 
advantage of newly installed plugins after a simple restart 
or refresh instead of having to create new instances every 
time something is changed (which would get to be a royal 
PITA in production use).

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com