title: Handle SQLAlchemy disconnect
body: <p>I'm using SQLAlchemy for my Flask application and I have just ran into a few problems with closed connection to my MySQL DB.</p>
  
  <p>I'm setting up my connection like this in my <code>__init__.py</code></p>
  
  <pre><code>engine = create_engine('mysql://user:pass@localhost/db', pool_recycle=3600)
  db = SQLAlchemy(app)
  </code></pre>
  
  <p>(I am using both ways to query my DB)</p>
  
  <p>I have just added the pool_recycle setting but I would like to be sure a lost connection can be restarted.</p>
  
  <p>Reading the following section:
  <a href="http://docs.sqlalchemy.org/en/latest/core/pooling.html#disconnect-handling-pessimistic" rel="nofollow">http://docs.sqlalchemy.org/en/latest/core/pooling.html#disconnect-handling-pessimistic</a></p>
  
  <p>I'm not really sure how to actually use this code, I don't want have to check the connection every time its being used in the code but rather have the connection restarted if it would close down. Is it possible to add a general event to handle DB disconnections?</p>