title: Is it odd that my SQLAlchemy MySQL connection always ends up sleeping?
body: <p>I have a Flask web application using SQLAlchemy with MySQL, and I have set up a scopedsession(). I also have a teardown_request handler that calls session.remove() after every request is finished. For some odd reason, if no requests are made on the web app for a day or more, the app gets "Operationalerror: MySQL Server has gone away".</p>
  
  <p>In my debugging  mission, I looked at SHOW PROCESSLIST and saw the following:</p>
  
  <pre><code>39817253 | sqladmin | my_host | kb_dev   | Sleep   |  174 |
  </code></pre>
  
  <p>The 174 is the number of seconds the connection from my application has been "sleeping". It keeps counting up if the application doesn't make another request.</p>
  
  <p>It seems like my application holds on to the connection to MySQL even after my request has finished! And there is usually only one process no matter how many requests I make with my application, simultaneously or not. </p>
  
  <p>My question is if it is normal for the connection to be "sleeping" this long? I'm pretty sure the extended sleeping is causing MySQL to cut the connection after a certain timeout which in turn is causing the "OperationalError: Mysql has gone away" error.                                                                                       </p>