From c750804914d0a636bacad58f2daf16a38ee9d3dc Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Thu, 28 Jun 2018 12:43:30 +0000 Subject: [PATCH] Bug 2339 - fournir une documentation utilisateur de physix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tentative de correction d'un bug qui cause l'erreur suivante d'apparaitre de temps en temps, à l'occasion du chargement de la page clusteruserguide : SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 139672342353664 and this is thread id 139672333960960 --- SimpaDbUtil.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SimpaDbUtil.py b/SimpaDbUtil.py index fdaaaef..6cc316d 100644 --- a/SimpaDbUtil.py +++ b/SimpaDbUtil.py @@ -84,7 +84,12 @@ class SqlFile(ISqlDatabaseBackend): os.remove(sqlite_db_path) except: pass - self._con = sqlite3.connect(sqlite_db_path) + check_same_thread = False + # this is to prevent the following error when run from apache/django : SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 139672342353664 and this is thread id 139672333960960 + # accordig to https://stackoverflow.com/questions/48218065/programmingerror-sqlite-objects-created-in-a-thread-can-only-be-used-in-that-sa this is ok, as long as there are no concurrent writes + # If set False, the returned connection may be shared across multiple threads. When using multiple threads with the same connection writing operations should be serialized by the user to avoid data corruption + # I hope it's safe here but I'm not 100% sure though. Anyway, if the database gets corrupt, it not a big deal since this memory resident database gets reconstructed from the sql file... + self._con = sqlite3.connect(sqlite_db_path, check_same_thread=check_same_thread) f = open(self._sql_file_path, 'r') sql = f.read() # watch out for built-in `str` #print(sql)