The problem started when I switched from sqlite to mysql. I use sqlalchemy and have tried configuring the pooling and time out using the code below, but no luck.
SQLALCHEMY_POOL_RECYCLE = 499
SQLALCHEMY_POOL_TIMEOUT = 20
I've took a look at the sqlalchemy docs for pooling http://docs.sqlalchemy.org/en/latest/core/pooling.html but I'm not sure which part of my code I'd implement it in. I see people using TRY and EXCEPT or some type of loop to reconnect.
This is what I'm working with. Any advice would be great =)
manage.py
import os
from app import create_app, db
from app.models import *
from flask.ext.script import Manager, Shell
app = create_app('default')
manager = Manager(app)
def make_shell_context():
return dict(app=app, db=db, Comment=Comment, ActivityLog=ActivityLog,
Appointment=Appointment)
manager.add_command("shell", Shell(make_context=make_shell_context))
if __name__ == '__main__':
manager.run()
app/__init__.py
from flask import Flask, render_template
import os
from flask_bootstrap import Bootstrap
from flask.ext.login import LoginManager
from flask.ext.mail import Mail
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.moment import Moment
from config import config
bootstrap = Bootstrap()
mail = Mail()
db = SQLAlchemy()
login_manager = LoginManager()
login_manager.session_protection = 'strong'
login_manager.login_view = 'main.login'
def create_app(config_name):
app = Flask(__name__)
app.config.from_object(config[config_name])
config[config_name].init_app(app)
bootstrap.init_app(app)
mail.init_app(app)
db.init_app(app)
login_manager.init_app(app)
from .main import main as main_blueprint
app.register_blueprint(main_blueprint)
from .promo import promo as promo_blueprint
app.register_blueprint(promo_blueprint)
return app