From d30060bf9119994b55c9fae86f60839674dcf530 Mon Sep 17 00:00:00 2001 From: echel0n Date: Thu, 5 Jun 2014 09:22:54 -0700 Subject: [PATCH] Fix for db locking issues --- sickbeard/db.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/sickbeard/db.py b/sickbeard/db.py index c771cc56..524a0a65 100644 --- a/sickbeard/db.py +++ b/sickbeard/db.py @@ -22,6 +22,7 @@ import os.path import re import threading import sqlite3 +import time import sickbeard from sqlalchemy import create_engine, exc @@ -102,7 +103,7 @@ class DBConnection: if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]: logger.log(u"DB error: " + ex(e), logger.WARNING) attempt += 1 - #time.sleep(cpu_presets[sickbeard.CPU_PRESET]) + time.sleep(1) else: logger.log(u"DB error: " + ex(e), logger.ERROR) raise @@ -126,17 +127,17 @@ class DBConnection: while attempt < 5: try: - with self.connection as trans: - for qu in querylist: - if len(qu) == 1: - if logTransaction: - logger.log(qu[0], logger.DEBUG) - sqlResult.append(trans.execute(qu[0])) - elif len(qu) > 1: - if logTransaction: - logger.log(qu[0] + " with args " + str(qu[1]), logger.DEBUG) - sqlResult.append(trans.execute(qu[0], qu[1])) + for qu in querylist: + if len(qu) == 1: + if logTransaction: + logger.log(qu[0], logger.DEBUG) + sqlResult.append(self.connection.execute(qu[0])) + elif len(qu) > 1: + if logTransaction: + logger.log(qu[0] + " with args " + str(qu[1]), logger.DEBUG) + sqlResult.append(self.connection.execute(qu[0], qu[1])) + self.connection.commit() logger.log(u"Transaction with " + str(len(querylist)) + u" queries executed", logger.DEBUG) return sqlResult except sqlite3.OperationalError, e: @@ -146,6 +147,7 @@ class DBConnection: if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]: logger.log(u"DB error: " + ex(e), logger.WARNING) attempt += 1 + time.sleep(1) else: logger.log(u"DB error: " + ex(e), logger.ERROR) raise @@ -182,7 +184,7 @@ class DBConnection: if "unable to open database file" in e.args[0] or "database is locked" in e.args[0]: logger.log(u"DB error: " + ex(e), logger.WARNING) attempt += 1 - #time.sleep(cpu_presets[sickbeard.CPU_PRESET]) + time.sleep(1) else: logger.log(u"DB error: " + ex(e), logger.ERROR) raise