Skip to content
Browse files

Fix problem with concurrent access to DB in separate threads.

This will let the web server work for the demo.
  • Loading branch information...
1 parent 7ccfd0d commit bf43aeaea250a8c89b1a6e37f294447612afa444 @JoshRosen committed
Showing with 6 additions and 3 deletions.
  1. +6 −3 database.py
View
9 database.py
@@ -106,7 +106,8 @@
String, ForeignKey, UniqueConstraint
from sqlalchemy.sql.expression import between, desc
from sqlalchemy.ext.declarative import declarative_base
-from sqlalchemy.orm import deferred, relationship, sessionmaker, join, backref
+from sqlalchemy.orm import deferred, relationship, sessionmaker, join, \
+ backref, scoped_session
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.interfaces import PoolListener
@@ -144,8 +145,10 @@ def connect(self, dbapi_con, con_record):
lambda x: x.decode('ascii', 'ignore').encode()
self._engine = create_engine(self._database_url,
listeners=[SetTextFactory()])
- self._sessionmaker = sessionmaker(bind=self._engine)
- self._session = self._sessionmaker()
+ self._sessionmaker = scoped_session(sessionmaker(bind=self._engine))
+ # Call classmethods on the scoped session instead of creating session
+ # instances.
+ self._session = self._sessionmaker
self.create_database_schema()
self._ontology_match_order = None # This is cached for performance.

0 comments on commit bf43aea

Please sign in to comment.
Something went wrong with that request. Please try again.