title: Does an application-wide exception handler make sense?
body: <p>Long story short, I have a substantial Python application that, among other things, does outcalls to "losetup", "mount", etc. on Linux.  Essentially consuming system resources that must be released when complete.</p>
  
  <p>If my application crashes, I want to ensure these system resources are properly released.</p>
  
  <p>Does it make sense to do something like the following?</p>
  
  <pre><code>def main():
      # TODO: main application entry point
      pass
  
  def cleanup():
      # TODO: release system resources here
      pass
  
  if __name__ == "__main__":
      try:
          main()
      except:
          cleanup()
          raise
  </code></pre>
  
  <p>Is this something that is typically done?  Is there a better way?  Perhaps the destructor in a singleton class?</p>