better sqlite connection handling
This commit is contained in:
parent
1a02698f06
commit
d6743ad2a6
@ -51,9 +51,6 @@ class SATool(cherrypy.Tool):
|
||||
def bind_session(self):
|
||||
cherrypy.engine.publish('bind', self.session)
|
||||
cherrypy.request.db = self.session
|
||||
con = cherrypy.request.db.connection().connection.connection
|
||||
if hasattr(con, "ping"): # not available on sqlite
|
||||
con.ping()
|
||||
|
||||
def commit_transaction(self):
|
||||
cherrypy.request.db = None
|
||||
|
@ -3,9 +3,9 @@ import sys
|
||||
import traceback
|
||||
from time import time
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.pool import StaticPool
|
||||
from sqlalchemy.pool import StaticPool, AssertionPool, NullPool # NOQA
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from photoapp.types import Base, Photo, PhotoSet # need to be loaded for orm setup
|
||||
from photoapp.types import Base, Photo, PhotoSet # NOQA need to be loaded for orm setup
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from collections import defaultdict
|
||||
from multiprocessing import Process
|
||||
@ -16,8 +16,11 @@ class PhotoLibrary(object):
|
||||
def __init__(self, db_path, lib_path, cache_path):
|
||||
self.path = lib_path
|
||||
self.cache_path = cache_path
|
||||
# TODO configure from env var
|
||||
# TODO use the right pool and connection args depending on the url
|
||||
# https://docs.sqlalchemy.org/en/13/core/pooling.html
|
||||
self.engine = create_engine('sqlite:///{}'.format(db_path),
|
||||
connect_args={'check_same_thread': False}, poolclass=StaticPool)
|
||||
connect_args={'check_same_thread': False}, poolclass=NullPool, pool_pre_ping=True)
|
||||
Base.metadata.create_all(self.engine)
|
||||
self.session = sessionmaker()
|
||||
self.session.configure(bind=self.engine)
|
||||
|
@ -2,7 +2,7 @@ backports.functools-lru-cache==1.5
|
||||
certifi==2019.6.16
|
||||
chardet==3.0.4
|
||||
cheroot==6.5.2
|
||||
CherryPy==18.1.1
|
||||
CherryPy==18.1.2
|
||||
contextlib2==0.5.5
|
||||
idna==2.8
|
||||
jaraco.functools==1.20
|
||||
|
Loading…
Reference in New Issue
Block a user