Skip to content

Commit

Permalink
using scoped_session, related to #133
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrasca committed Jan 13, 2018
1 parent b581e91 commit b74670e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions bauble/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ def open(uri, verify=True, show_error_dialogs=False):

# ** WARNING: this can print your passwd
logger.debug('db.open(%s)' % uri)
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import sessionmaker, scoped_session
global engine
new_engine = None

from sqlalchemy.pool import NullPool, SingletonThreadPool
from sqlalchemy.pool import SingletonThreadPool
from bauble.prefs import testing
poolclass = testing and SingletonThreadPool or NullPool

poolclass = SingletonThreadPool
new_engine = sa.create_engine(uri, echo=SQLALCHEMY_DEBUG,
implicit_returning=False,
Expand All @@ -298,8 +298,8 @@ def _bind():
def temp():
import inspect
logger.debug('creating session %s' % str(inspect.stack()[1]))
return sessionmaker(bind=engine, autoflush=False)()
Session = sessionmaker(bind=engine, autoflush=False)
return scoped_session(sessionmaker(bind=engine, autoflush=False))()
Session = scoped_session(sessionmaker(bind=engine, autoflush=False))
Session = temp

if new_engine is not None and not verify:
Expand Down

0 comments on commit b74670e

Please sign in to comment.