From 0e1ec5034e2b6b199c5829e749f0889ebc55ff3a Mon Sep 17 00:00:00 2001 From: blitzmann Date: Tue, 11 Aug 2020 12:44:55 -0400 Subject: [PATCH] Fix for #1564 - using memory database in multiple threads. See also: https://docs.sqlalchemy.org/en/13/dialects/sqlite.html#using-a-memory-database-in-multiple-threads --- cps/db.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cps/db.py b/cps/db.py index 1296c84a..02a0aa60 100644 --- a/cps/db.py +++ b/cps/db.py @@ -32,6 +32,7 @@ from sqlalchemy import String, Integer, Boolean, TIMESTAMP, Float from sqlalchemy.orm import relationship, sessionmaker, scoped_session from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.exc import OperationalError +from sqlalchemy.pool import StaticPool from flask_login import current_user from sqlalchemy.sql.expression import and_, true, false, text, func, or_ from babel import Locale as LC @@ -386,7 +387,8 @@ class CalibreDB(threading.Thread): self.engine = create_engine('sqlite://', echo=False, isolation_level="SERIALIZABLE", - connect_args={'check_same_thread': False}) + connect_args={'check_same_thread': False}, + poolclass=StaticPool) self.engine.execute("attach database '{}' as calibre;".format(dbpath)) self.engine.execute("attach database '{}' as app_settings;".format(app_db_path))