title: Pyramid: run code at exit
body: <p>How would you run an exit script on pyramid that have access to configuration settings?</p>
  
  <p>I want to close the database connection when exiting the server or when there's an error, but cannot find a way to access the exit loop. I found <a href="https://stackoverflow.com/questions/7484366/run-code-at-pyramid-shutdown">this SO question</a>, but I don't know how to access the Configurator object to close the connection that way.</p>