From 9932a8199f65ad5645707890ccb72d60dff283c3 Mon Sep 17 00:00:00 2001 From: Jake Moshenko Date: Mon, 7 Jul 2014 17:06:53 -0400 Subject: [PATCH] Disconnect from read slaves when the request ends. --- application.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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