diff roundup/backends/back_sqlite.py @ 2847:fddbbeb581bc

sqlite_busy_timeout is not supported in pysqlite 1.1 (SQLite 3.x). have to install sqlite_busy_handler instead.
author Alexander Smishlajev <a1s@users.sourceforge.net>
date Sun, 31 Oct 2004 09:57:10 +0000
parents d3b3f1b3d59e
children c5530df3aaa6 240a24f1e69f
line wrap: on
line diff
--- a/roundup/backends/back_sqlite.py	Sun Oct 31 08:56:39 2004 +0000
+++ b/roundup/backends/back_sqlite.py	Sun Oct 31 09:57:10 2004 +0000
@@ -1,4 +1,4 @@
-# $Id: back_sqlite.py,v 1.35 2004-10-16 12:52:53 a1s Exp $
+# $Id: back_sqlite.py,v 1.36 2004-10-31 09:57:10 a1s Exp $
 '''Implements a backend for SQLite.
 
 See https://pysqlite.sourceforge.net/ for pysqlite info
@@ -55,6 +55,21 @@
         hyperdb.Multilink : lambda x: x,    # used in journal marshalling
     }
 
+    def sqlite_busy_handler(self, data, table, count):
+        """invoked whenever SQLite tries to access a database that is locked"""
+        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 expired - no more retries
+            return 0
+        # sleep adaptively as retry count grows,
+        # starting from about half a second
+        time_to_sleep = 0.01 * (2 << min(5, count))
+        time.sleep(time_to_sleep)
+        return 1
+
     def sql_open_connection(self):
         '''Open a standard, non-autocommitting connection.
 
@@ -70,7 +85,7 @@
         conn = sqlite.connect(db=db)
         # set a 30 second timeout (extraordinarily generous) for handling
         # locked database
-        conn.db.sqlite_busy_timeout(30 * 1000)
+        conn.db.sqlite_busy_handler(self.sqlite_busy_handler)
         cursor = conn.cursor()
         return (conn, cursor)
 

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