diff --git a/application.py b/application.py index adccb5fc2..2fb79835b 100644 --- a/application.py +++ b/application.py @@ -2,11 +2,12 @@ import logging import logging.config import uuid +from peewee import Proxy + from app import app as application from flask import request, Request from util.names import urn_generator - -from data.model import db as model_db +from data.model import db as model_db, read_slave # Turn off debug logging for boto logging.getLogger('boto').setLevel(logging.CRITICAL) @@ -76,6 +77,10 @@ def close_db(exc): logger.debug('Disconnecting from database.') db.close() + if read_slave.obj is not None and not read_slave.is_closed(): + logger.debug('Disconnecting from read slave.') + read_slave.close() + application.teardown_request(close_db) application.request_class = RequestWithId