code: def _exit_handler(self):
          
  
          # TODO: consider handling sys.stderr/sys.stdout exceptions related to
          # TODO (cont.): order of interpreter vs. subprocess shutdown signal receipt.
          # TODO (cont.): see https://bugs.python.org/issue11380
  
  
          # Make the cleanup file executable if it exists
          if os.path.isfile(self.cleanup_file):
              # Make the cleanup file self destruct.
              with open(self.cleanup_file, "a") as myfile:
                  myfile.write("rm " + self.cleanup_file + "\n")
              os.chmod(self.cleanup_file, 0o755)
  
          # If the pipeline hasn't completed successfully, or already been marked
          # as failed, then mark it as failed now.
  
          if not self._has_exit_status:
              print("Pipeline status: {}".format(self.status))
              self.fail_pipeline(Exception("Pipeline failure. See details above."))
  
          if self.tee:
              self.tee.kill()
docs: This function I register with atexit to run whenever the script is completing.
          A catch-all for uncaught exceptions, setting status flag file to failed.