python - Flask-SQLAlchemy: Can't reconnect until invalid transaction is rolled back -


so using amazon web services rds run mysql server , using python's flask framework run application server , flask-sqlalchemy interface rds.

my app config.py

sqlalchemy_database_uri = '<rds host>' sqlalchemy_pool_recycle = 60 

my __ init __.py

from flask import flask flask.ext.sqlalchemy import sqlalchemy  application = flask(__name__) application.config.from_object('config') db = sqlalchemy(application) 

i have main application.py

from flask import flask application import db import flask.ext.restless application.models import person  application = flask(__name__) application.debug=true db.init_app(application)  @application.route('/') def index():     return "hello, world!"  manager = flask.ext.restless.apimanager(application, flask_sqlalchemy_db=db) manager.create_api(person, methods=['get','post', 'delete'])  if __name__ == '__main__':     application.run(host='0.0.0.0') 

the models.py

class person(db.model):     __bind_key__= 'people'     id = db.column(db.integer, primary_key=true)     firstname = db.column(db.string(80))     lastname = db.column(db.string(80))     email = db.column(db.string(80))      def __init__(self, firstname=none, lastname=none, email=none):         self.firstname = firstname         self.lastname = lastname         self.email = email 

i have script populate database testing purposes after db creation , app start:

from application import db application.models import person  person = person('bob', 'jones', 'bob@website.net') db.session.add(person) db.session.commit() 

once i've reset database db.drop_all() , db.create_all() start application.py , script populate database.

the server respond correct json if come , check hours later, error need rollback or 2006 error mysql server has gone away.

people suggested change timeout settings on mysql server hasn't fixed anything. here settings:

innodb_lock_wait_timeout = 3000 max_allowed_packet       = 65536 net_write_timeout        = 300 wait_timeout             = 300 

then when @ rds monitor, shows mysql server kept connection open quite while until timeout. correct me if i'm wrong isn't connection supposed closed after it's finished? seems application server keeps making sure database connection exists , when mysql server times out, flask/flask-sqlalchemy throws error , brings down app server it.

any suggestions appreciated, thanks!

i think did adding

db.init_app(application) 

in application.py, haven't had error since.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -