code: def save_state(self):
          
          if not self.filename:
              self.logger.error('Filename not specified. Could not save state')
              return
          self.logger.debug('Saving system state to %s', self.filename)
          for i in reversed(range(self.num_state_backups)):
              fname = self.filename if i == 0 else '%s.%d' % (self.filename, i)
              new_fname = '%s.%d' % (self.filename, i+1)
              try:
                  os.rename(fname, new_fname)
              except FileNotFoundError:
                  pass
  
          with open(self.filename, 'wb') as file, self.worker_thread.queue.mutex:
              obj_list = list(self.objects)
              config = {obj.name: obj.status for obj in obj_list
                        if getattr(obj, 'user_editable', False)}
              data = obj_list, config
              pickle.dump((STATEFILE_VERSION, data), file, pickle.HIGHEST_PROTOCOL)
docs: Save state of the system to a dump file :attr:`System.filename`