code: def RemoveTask(self, task):
      
      with self._lock:
        if task.identifier not in self._tasks_abandoned:
          raise KeyError('Task {0:s} was not abandoned.'.format(task.identifier))
  
        if not task.has_retry:
          raise KeyError(
              'Will not remove a task {0:s} without retry task.'.format(
                  task.identifier))
  
        del self._tasks_abandoned[task.identifier]
  
        logger.debug('Removed task {0:s}.'.format(task.identifier))
docs: Removes an abandoned task.
  
      Args:
        task (Task): task.
  
      Raises:
        KeyError: if the task was not abandoned or the task was abandoned and
            was not retried.