Skip to content

Commit

Permalink
Fix problem with concurrent access to DB in separate threads.
Browse files Browse the repository at this point in the history
This will let the web server work for the demo.
  • Loading branch information
JoshRosen committed Mar 16, 2011
1 parent 7ccfd0d commit bf43aea
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.

Expand Down

0 comments on commit bf43aea

Please sign in to comment.