|
@@ -1,14 +1,14 @@
|
|
|
from contextlib import contextmanager
|
|
|
|
|
|
from sqlalchemy import create_engine
|
|
|
-from sqlalchemy.orm import sessionmaker
|
|
|
+from sqlalchemy.orm import sessionmaker, scoped_session
|
|
|
|
|
|
from config import DB_FILE
|
|
|
from command_system import ModelBase
|
|
|
|
|
|
|
|
|
engine = create_engine("sqlite:///" + DB_FILE)
|
|
|
-Session = sessionmaker(bind=engine)
|
|
|
+Session = scoped_session(sessionmaker(bind=engine))
|
|
|
|
|
|
|
|
|
def init_db():
|
|
@@ -23,6 +23,9 @@ def session_scope():
|
|
|
yield session
|
|
|
session.commit()
|
|
|
except:
|
|
|
+ # TODO there is some worry that this would rollback things in other threads...
|
|
|
+ # we should probably find a more correct solution for managing the threaded
|
|
|
+ # db access, but the risk is fairly low at this point.
|
|
|
session.rollback()
|
|
|
raise
|
|
|
finally:
|