[Zodb-checkins] CVS: Zope3/src/persistence - cache.py:1.6
Tim Peters
tim.one@comcast.net
Mon, 17 Mar 2003 14:44:02 -0500
Update of /cvs-repository/Zope3/src/persistence
In directory cvs.zope.org:/tmp/cvs-serv18615/src/persistence
Modified Files:
cache.py
Log Message:
Cache.incrgc(): If garbage collection happens to occur while iterating
over __active, weakrefs can cause __active to change size. This in turn
could cause a mysterious "Transaction failed during second phase
of two-phase commit" TransactionError. The cure is to use .items()
instead of .iteritems().
=== Zope3/src/persistence/cache.py 1.5 => 1.6 ===
--- Zope3/src/persistence/cache.py:1.5 Tue Mar 11 17:09:06 2003
+++ Zope3/src/persistence/cache.py Mon Mar 17 14:44:01 2003
@@ -90,12 +90,14 @@
now = int(time() % 86400)
# Implement a trivial LRU cache by sorting the items by access
- # time and trundling over the list until we've reached out
+ # time and trundling over the list until we've reached our
# target size. The number of objects in the cache should be
# relatively small (thousands) so the memory for the list is
- # pretty minimal.
+ # pretty minimal. Caution: Don't use iteritems(). Because of
+ # weakrefs, if garbage collection happens to occur, __active
+ # can change size.
L = []
- for oid, ob in self.__active.iteritems():
+ for oid, ob in self.__active.items():
if ob is not None:
ob = ob()
# The _p_atime field is seconds since the start of the day.