aboutsummaryrefslogtreecommitdiff
path: root/wqflask
diff options
context:
space:
mode:
authorPjotr Prins2016-06-23 09:53:45 +0000
committerPjotr Prins2016-06-23 09:53:45 +0000
commitf4200d002cce2edddddac67c55a75c2f1883ea2f (patch)
tree51df2016140db5601c7d768685fc23f71a48d6d5 /wqflask
parent1665de1e732682fa2e3a5d37b5bece325158eeeb (diff)
downloadgenenetwork2-f4200d002cce2edddddac67c55a75c2f1883ea2f.tar.gz
Clean up database connector after session
Diffstat (limited to 'wqflask')
-rw-r--r--wqflask/wqflask/views.py14
1 files changed, 12 insertions, 2 deletions
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():