diff roundup/backends/back_sqlite.py @ 4415:3e35233ea93c

new rdbms config item sqlite_timeout... ...makes the previously hard-coded timeout of 30 seconds configurable. This is the time a client waits for the locked database to become free before giving up. Used only for SQLite backend.
author Ralf Schlatterbeck <schlatterbeck@users.sourceforge.net>
date Tue, 07 Sep 2010 15:42:04 +0000
parents 13b3155869e0
children 9655a1b65974
line wrap: on
line diff
--- a/roundup/backends/back_sqlite.py	Tue Sep 07 14:49:52 2010 +0000
+++ b/roundup/backends/back_sqlite.py	Tue Sep 07 15:42:04 2010 +0000
@@ -75,11 +75,11 @@
 
     def sqlite_busy_handler(self, data, table, count):
         """invoked whenever SQLite tries to access a database that is locked"""
+        now = time.time()
         if count == 1:
-            # use a 30 second timeout (extraordinarily generous)
-            # for handling locked database
-            self._busy_handler_endtime = time.time() + 30
-        elif time.time() > self._busy_handler_endtime:
+            # Timeout for handling locked database (default 30s)
+            self._busy_handler_endtime = now + self.config.RDBMS_SQLITE_TIMEOUT
+        elif now > self._busy_handler_endtime:
             # timeout expired - no more retries
             return 0
         # sleep adaptively as retry count grows,
@@ -100,13 +100,13 @@
 
         db = os.path.join(self.config.DATABASE, 'db')
         logging.getLogger('hyperdb').info('open database %r'%db)
-        # set a 30 second timeout (extraordinarily generous) for handling
-        # locked database
+        # set timeout (30 second default is extraordinarily generous)
+        # for handling locked database
         if sqlite_version == 1:
             conn = sqlite.connect(db=db)
             conn.db.sqlite_busy_handler(self.sqlite_busy_handler)
         else:
-            conn = sqlite.connect(db, timeout=30)
+            conn = sqlite.connect(db, timeout=self.config.RDBMS_SQLITE_TIMEOUT)
             conn.row_factory = sqlite.Row
 
         # pysqlite2 / sqlite3 want us to store Unicode in the db but

Roundup Issue Tracker: http://roundup-tracker.org/