[Zope] Zope 2.9 Product Refreshing
Peter Bengtsson
peter at fry-it.com
Mon Aug 21 05:13:41 EDT 2006
Dieter Maurer wrote:
> Peter Bengtsson wrote at 2006-8-18 18:53 +0100:
>> ...
>> One last odd clue, when I refresh my product (eg. MyProduct) in zope
>> 2.9.4, actual something happens. My product is very very simple and
>> it's one main class has a method called index_html() that looks like
>> this:
>>
>>
>>from DateTime import DateTime
>> def index_html(self, REQUEST, RESPONSE):
>> """ doc str """
>> return str(DateTime())
>>
>> It works fine. After I manually refresh the product through the
>> Control_Panel, I get an error in index_html() because now 'DateTime'
>> has become None and thus can't be called with DateTime().
>> Does that help you help me?
>
> Global variables apparently becoming "None" is a sign
> that you are using an old (pre refresh) version of a function
> ("index_html" in your case).
>
> When a module is released, some Python magic arranges that
> all its variables are rebound to "None".
>
> When the function accesses one of its globals, it then appears as "None".
>
>
> If you have accessed the "index_html" via a persistent instance,
> then the "resetCaches" seems not to have done what we expect
> (it should have caused the connection cache to be dropped and
> a new instance loaded from the storage with the new class definition).
>
The function resetCaches() and self._resetCache() in ZODB.Connection
hasn't changed from zope 2.8 to zope 2.9.
==== the code =========
global_reset_counter = 0
def resetCaches():
"""Causes all connection caches to be reset as connections are
reopened.
Zope's refresh feature uses this. When you reload Python modules,
instances of classes continue to use the old class definitions.
To use the new code immediately, the refresh feature asks ZODB to
clear caches by calling resetCaches(). When the instances are
loaded by subsequent connections, they will use the new class
definitions.
"""
global global_reset_counter
global_reset_counter += 1
class Connection(ExportImport, object):
....
def _resetCache(self):
"""Creates a new cache, discarding the old one.
See the docstring for the resetCaches() function.
"""
self._reset_counter = global_reset_counter
self._invalidated.clear()
cache_size = self._cache.cache_size
self._cache = cache = PickleCache(self, cache_size)
========================
--
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com
More information about the Zope
mailing list