title: Flask and sqlalchemy: handling sessions
body: <p>I recently started using Flask + Sqlalchemy for my project, and have been noticing 500 errors after a day of leaving the server up. I think this is due to the database session timing out, but I'm not sure. Are we supposed to make a new session for every request, or is it one for one the Flask app starts?
  I have this at the top of my app.py</p>
  
  <pre><code>from sqlalchemy import Column, ForeignKey, Integer, String, create_engine, func, cast, Float 
  from sqlalchemy.ext.declarative import declarative_base 
  from sqlalchemy.orm import relationship,scoped_session,sessionmaker,aliased
  engine = createengine(DB_PATH) 
  Session = sessionmaker(bind=engine) 
  session = Session() 
  app = Flask(name_)
  </code></pre>
  
  <p>And then for all queries in the views, I do something like: "session.query(Table)..."
  Is this wrong, should I be making a session for every endpoint call?</p>