From fdc62aa62326924daf8bb8850e134d9c0149cfaa Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Mon, 3 Oct 2016 18:59:10 -0500 Subject: [PATCH] Retry dbcommit For some reason, Kodi doesn't always trigger the video database scan stopped event keeping the add-on waiting forever. Try committing after 10 sec and catching the error if the database is truly locked. --- resources/lib/librarysync.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/resources/lib/librarysync.py b/resources/lib/librarysync.py index d9bbfa26..2a2056cd 100644 --- a/resources/lib/librarysync.py +++ b/resources/lib/librarysync.py @@ -192,12 +192,17 @@ class LibrarySync(threading.Thread): def dbCommit(self, connection): # Central commit, verifies if Kodi database update is running kodidb_scan = window('emby_kodiScan') == "true" + count = 0 while kodidb_scan: log.info("Kodi scan is running. Waiting...") kodidb_scan = window('emby_kodiScan') == "true" + if count == 10: + log.info("Flag still active, but will try to commit") + window('emby_kodiScan', clear=True) + if self.shouldStop(): log.info("Commit unsuccessful. Sync terminated.") break @@ -206,9 +211,18 @@ class LibrarySync(threading.Thread): # Abort was requested while waiting. We should exit log.info("Commit unsuccessful.") break - else: + + count += 1 + + try: connection.commit() log.info("Commit successful.") + except sqlite3.OperationalError as error: + log.error(error) + if "database is locked" in error: + log.info("retrying...") + window('emby_kodiScan', value="true") + self.dbCommit(connection) def fullSync(self, manualrun=False, repair=False): # Only run once when first setting up. Can be run manually.