code: def run(self):
          
          log_total = True
  
          try:
              try:
                  # Preparation steps
                  self.get_options()
  
                  # Template method with the tool's main loop
                  self.mainloop()
              except error.LoggableError, exc:
                  if self.options.debug:
                      raise
  
                  # Log errors caused by invalid user input
                  try:
                      msg = str(exc)
                  except UnicodeError:
                      msg = unicode(exc, "UTF-8")
                  self.LOG.error(msg)
                  sys.exit(error.EX_SOFTWARE)
              except KeyboardInterrupt, exc:
                  if self.options.debug:
                      raise
  
                  sys.stderr.write("\n\nAborted by CTRL-C!\n")
                  sys.stderr.flush()
                  sys.exit(error.EX_TEMPFAIL)
              except IOError, exc:
                  # [Errno 32] Broken pipe?
                  if exc.errno == errno.EPIPE:
                      sys.stderr.write("\n%s, exiting!\n" % exc)
                      sys.stderr.flush()
  
                      # Monkey patch to prevent an exception during logging shutdown
                      try:
                          handlers = logging._handlerList
                      except AttributeError:
                          pass
                      else:
                          for handler in handlers:
                              try:
                                  handler.flush = lambda *_: None
                              except AttributeError:
                                  pass # skip special handlers
  
                      log_total = False
                      sys.exit(error.EX_IOERR)
                  else:
                      raise
          finally:
              # Shut down
              if log_total and self.options:  ## No time logging on --version and such
                  running_time = time.time() - self.startup
                  self.LOG.log(self.STD_LOG_LEVEL, "Total time: %.3f seconds." % running_time)
              logging.shutdown()
  
          # Special exit code?
          if self.return_code:
              sys.exit(self.return_code)
docs: The main program skeleton.