title: How teardown_request() works with Python- Flask?
body: <p>I received internal error with message:</p>
  
  <pre><code>"TimeoutError: QueuePool limit of size 5 overflow 10 reached, connection timed out, timeout 30"
  </code></pre>
  
  <p>and searching online gave teardown_request() solution :</p>
  
  <pre><code>@app.teardown_request
  def checkin_db(exc):
      try:
          print "Removing db session."
          db.session.remove()
      except AttributeError:
          pass
  </code></pre>
  
  <p>Now timeout error is gone. But I didn't understand teardown_request completely,  look like db.session.remove() will be invoked after every request ? or every error? Is it safe to use this code?</p>