From 79a7f2291d7ff2bf8db43ea9953df8afbac7650f Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sun, 10 Apr 2016 16:11:41 +0200 Subject: [PATCH] Now the sql connections are closed automatically when the requests are finished --- paramecio/cromosoma/webmodel.py | 13 ++++++++++++- paramecio/index.py | 5 ++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/paramecio/cromosoma/webmodel.py b/paramecio/cromosoma/webmodel.py index 86258c3..d916052 100644 --- a/paramecio/cromosoma/webmodel.py +++ b/paramecio/cromosoma/webmodel.py @@ -835,8 +835,19 @@ class WebModel: @staticmethod def close(): + + connection_to_delete=[] + WebModel.make_connection=SqlClass.connect_to_db - SqlClass.close(SqlClass) + + for key in SqlClass.connection: + SqlClass.close(SqlClass, key) + #connection_to_delete.append(key) + + SqlClass.connection={} + + #for key in connection_to_delete: + #del SqlClass.connection[key] @staticmethod def escape_sql(value): diff --git a/paramecio/index.py b/paramecio/index.py index 1767dbd..60f8142 100644 --- a/paramecio/index.py +++ b/paramecio/index.py @@ -4,6 +4,7 @@ from bottle import route, get, post, run, default_app, abort, request, static_fi from settings import config, modules from beaker.middleware import SessionMiddleware from mimetypes import guess_type +from paramecio.cromosoma.webmodel import WebModel #Prepare links for static. #WARNING: only use this feature in development, not in production. @@ -118,7 +119,9 @@ if config.ssl==True: app = application = default_app() -app.add_hook('before_request', print_cookie) +#app.add_hook('before_request', print_cookie) + +app.add_hook('after_request', WebModel.close) if config.session_enabled==True: #Create dir for sessions