From f4200d002cce2edddddac67c55a75c2f1883ea2f Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Thu, 23 Jun 2016 09:53:45 +0000 Subject: Clean up database connector after session --- wqflask/wqflask/views.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index ac45815b..10e53e5e 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -48,7 +48,7 @@ from wqflask.wgcna import wgcna_analysis from wqflask.ctl import ctl_analysis from utility import temp_data -from utility.tools import TEMPDIR,USE_REDIS,USE_GN_SERVER,GN_SERVER_URL +from utility.tools import SQL_URI,TEMPDIR,USE_REDIS,USE_GN_SERVER,GN_SERVER_URL from base import webqtlFormData from base.webqtlConfig import GENERATED_IMAGE_DIR @@ -58,13 +58,23 @@ from pprint import pformat as pf from wqflask import user_manager from wqflask import collect +from wqflask.database import db_session import utility.logger logger = utility.logger.getLogger(__name__ ) @app.before_request def connect_db(): - g.db = sqlalchemy.create_engine(app.config['SQL_URI']) + db = getattr(g, '_database', None) + if db is None: + logger.debug("Get new database connector") + g.db = g._database = sqlalchemy.create_engine(SQL_URI) + logger.debug(g.db) + +@app.teardown_appcontext +def shutdown_session(exception=None): + logger.debug("remove db_session") + db_session.remove() #@app.before_request #def trace_it(): -- cgit v1.2.3