code: def on_shutdown(self):
          
  
          self.in_shutdown = True
  
          self.logger.debug('on_shutdown, stopped=%s, ended=%s, early_stop=%s, stop_requested=%s'
                            % (str(self.stopped), str(self.ended), str(self.in_early_stop), str(self.stop_requested)))
          if self.stopped or self.ended:
              # make really sure, ssh connection closed
              self.client.close()
              return
  
          if self.in_early_stop:
              self.done()
              return
  
          if self.stop_requested:
              # when SIGINT has been triggered
              if self.stop_requested_force:
                  if not self.is_master_process():
                      # if not master process, we just stop everything. status/progress is set by master
                      self.stop(force_exit=True)
                  else:
                      # master process
                      self.fail('Force stopped.', force_exit=True)
              else:
                  if not self.is_master_process():
                      # if not master process, we just stop everything. status/progress is set by master
                      self.stop()
                  else:
                      # master process
                      self.abort()
  
              return
  
          if hasattr(sys, 'last_value'):
              # sys.last_value contains a exception, when there was an uncaught one
              if isinstance(sys.last_value, KeyboardInterrupt):
                  # can only happen when KeyboardInterrupt has been raised manually
                  # since the one from the default sigint handler will never reach here
                  # since we catch the sigint signal and sys.exit() before the default sigint handler
                  # is able to raise KeyboardInterrupt
                  self.abort()
              else:
                  self.fail(type(sys.last_value).__name__ + ': ' + str(sys.last_value))
  
          elif self.running:
              self.done()
docs: Shutdown routine. Sets the last progress (done, aborted, failed) and tries to send last logs and git commits.
          Also makes sure the ssh connection is closed (thus, the job marked as offline).
  
          Is triggered by atexit.register().