Skip to content

Commit

Permalink
Use scoped_session instead of a plain session for thread safety, hope…
Browse files Browse the repository at this point in the history
…fully.
  • Loading branch information
mobiusklein committed Jan 5, 2024
1 parent 5a8e4c6 commit 594ebd1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions psims/controlled_vocabulary/unimod.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
UnicodeText, Boolean, event)
from sqlalchemy import exc as sa_exc
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import sessionmaker, scoped_session

from six import string_types as basestring

Expand Down Expand Up @@ -705,7 +705,7 @@ def create(doc_path, output_path="sqlite://"):
tree = preprocess_xml(doc_path)
engine = create_engine(output_path)
Base.metadata.create_all(engine)
session = sessionmaker(bind=engine, autoflush=False)()
session = scoped_session(sessionmaker(bind=engine, autoflush=False))
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=sa_exc.SAWarning)
for model in model_registry:
Expand All @@ -728,7 +728,7 @@ def create(doc_path, output_path="sqlite://"):
def session(path="sqlite:///unimod.db"):
engine = create_engine(path)
Base.metadata.create_all(engine)
session = sessionmaker(bind=engine, autoflush=False)()
session = scoped_session(sessionmaker(bind=engine, autoflush=False))
return session


Expand Down

0 comments on commit 594ebd1

Please sign in to comment.