From 3a2686be246e17790c138c2072c8e7edfe14a753 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sun, 22 Dec 2013 00:45:33 +0200 Subject: [PATCH 1/2] Attempt to fix bug #1154467 by retrying the commit if it fails --- openlp/plugins/bibles/lib/db.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index 3def6bc3e..a638040fb 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -35,6 +35,7 @@ import sqlite3 from PyQt4 import QtCore from sqlalchemy import Column, ForeignKey, or_, Table, types, func +from sqlalchemy.exc import OperationalError from sqlalchemy.orm import class_mapper, mapper, relation from sqlalchemy.orm.exc import UnmappedClassError @@ -48,6 +49,7 @@ log = logging.getLogger(__name__) RESERVED_CHARACTERS = u'\\.^$*+?{}[]()' + class BibleMeta(BaseModel): """ Bible Meta Data @@ -257,7 +259,11 @@ class BibleDB(QtCore.QObject, Manager): text=verse_text ) self.session.add(verse) - self.session.commit() + try: + self.session.commit() + except OperationalError: + # Try again. If it fails again, let the exception happen + self.session.commit() def create_verse(self, book_id, chapter, verse, text): """ @@ -363,7 +369,7 @@ class BibleDB(QtCore.QObject, Manager): ``book`` The name of the book, according to the selected language. - + ``language_selection`` The language selection the user has chosen in the settings section of the Bible. From 4fdd9708b0536d409491cc9efb9ab7218675732f Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sun, 29 Dec 2013 00:20:13 +0200 Subject: [PATCH 2/2] Add a 10ms wait before trying again. --- openlp/plugins/bibles/lib/db.py | 6 ++++-- openlp/plugins/remotes/lib/httpserver.py | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/bibles/lib/db.py b/openlp/plugins/bibles/lib/db.py index a638040fb..8d15277a2 100644 --- a/openlp/plugins/bibles/lib/db.py +++ b/openlp/plugins/bibles/lib/db.py @@ -32,6 +32,7 @@ import logging import os import re import sqlite3 +import time from PyQt4 import QtCore from sqlalchemy import Column, ForeignKey, or_, Table, types, func @@ -262,7 +263,8 @@ class BibleDB(QtCore.QObject, Manager): try: self.session.commit() except OperationalError: - # Try again. If it fails again, let the exception happen + # Wait 10ms and try again. + time.sleep(0.01) self.session.commit() def create_verse(self, book_id, chapter, verse, text): @@ -1067,7 +1069,7 @@ class OldBibleDB(QtCore.QObject, Manager): QtCore.QObject.__init__(self) if u'path' not in kwargs: raise KeyError(u'Missing keyword argument "path".') - if u'file' not in kwargs: + if u'file' not in kwargs: raise KeyError(u'Missing keyword argument "file".') if u'path' in kwargs: self.path = kwargs[u'path'] diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index db49bed96..3b2da6949 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -593,8 +593,11 @@ class HttpConnection(object): for header, value in response.headers.iteritems(): http += '%s: %s\r\n' % (header, value) http += '\r\n' - self.socket.write(http) - self.socket.write(response.content) + if self.socket: + # Write to the socket if it's open, else ignore it. + # See http://support.openlp.org/scp/tickets.php?id=2112 + self.socket.write(http) + self.socket.write(response.content) def disconnected(self): """