[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/BaseStorage.py Added some lock-debugging support.
Jim Fulton
jim at zope.com
Sat Nov 1 14:07:33 EDT 2008
Log message for revision 92740:
Added some lock-debugging support.
Changed:
U ZODB/trunk/src/ZODB/BaseStorage.py
-=-
Modified: ZODB/trunk/src/ZODB/BaseStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/BaseStorage.py 2008-11-01 18:07:29 UTC (rev 92739)
+++ ZODB/trunk/src/ZODB/BaseStorage.py 2008-11-01 18:07:33 UTC (rev 92740)
@@ -32,7 +32,9 @@
log = logging.getLogger("ZODB.BaseStorage")
+import sys
+
class BaseStorage(UndoLogCompatible):
"""Base class that supports storage implementations.
@@ -81,13 +83,15 @@
log.debug("create storage %s", self.__name__)
# Allocate locks:
- l = threading.RLock()
- self._lock_acquire = l.acquire
- self._lock_release = l.release
- l = threading.Lock()
- self._commit_lock_acquire = l.acquire
- self._commit_lock_release = l.release
+ self.__lock = threading.RLock()
+ self.__commit_lock = threading.Lock()
+ # Comment out the following 4 lines to debug locking:
+ self._lock_acquire = self.__lock.acquire
+ self._lock_release = self.__lock.release
+ self._commit_lock_acquire = self.__commit_lock.acquire
+ self._commit_lock_release = self.__commit_lock.release
+
t = time.time()
t = self._ts = TimeStamp(*(time.gmtime(t)[:5] + (t%60,)))
self._tid = repr(t)
@@ -102,6 +106,45 @@
else:
self._oid = oid
+ ########################################################################
+ # The following methods are normally overridden on instances,
+ # except when debugging:
+
+ def _lock_acquire(self, *args):
+ f = sys._getframe(1)
+ sys.stdout.write("[la(%s:%s)\n" % (f.f_code.co_filename, f.f_lineno))
+ sys.stdout.flush()
+ self.__lock.acquire(*args)
+ sys.stdout.write("la(%s:%s)]\n" % (f.f_code.co_filename, f.f_lineno))
+ sys.stdout.flush()
+
+ def _lock_release(self, *args):
+ f = sys._getframe(1)
+ sys.stdout.write("[lr(%s:%s)\n" % (f.f_code.co_filename, f.f_lineno))
+ sys.stdout.flush()
+ self.__lock.release(*args)
+ sys.stdout.write("lr(%s:%s)]\n" % (f.f_code.co_filename, f.f_lineno))
+ sys.stdout.flush()
+
+ def _commit_lock_acquire(self, *args):
+ f = sys._getframe(1)
+ sys.stdout.write("[ca(%s:%s)\n" % (f.f_code.co_filename, f.f_lineno))
+ sys.stdout.flush()
+ self.__commit_lock.acquire(*args)
+ sys.stdout.write("ca(%s:%s)]\n" % (f.f_code.co_filename, f.f_lineno))
+ sys.stdout.flush()
+
+ def _commit_lock_release(self, *args):
+ f = sys._getframe(1)
+ sys.stdout.write("[cr(%s:%s)\n" % (f.f_code.co_filename, f.f_lineno))
+ sys.stdout.flush()
+ self.__commit_lock.release(*args)
+ sys.stdout.write("cr(%s:%s)]\n" % (f.f_code.co_filename, f.f_lineno))
+ sys.stdout.flush()
+
+ #
+ ########################################################################
+
def sortKey(self):
"""Return a string that can be used to sort storage instances.
More information about the Zodb-checkins
mailing list