title: Call function when Flask is stopped
body: <p>Is there a way to call a function when Flask is killed? I want to run some server teardown tasks to gracefully stop my application.</p>
  
  <p>Also, is there a similar analog for Flask startup? I'm currently putting all my startup code in the same file that calls <code>app = Flask(__name__)</code> - not sure if that's good practice.</p>
  
  <p>Thanks!</p>