code: def CompleteTask(self, task):
      
      with self._lock:
        if task.identifier not in self._tasks_merging:
          raise KeyError('Task {0:s} was not merging.'.format(task.identifier))
  
        self.SampleTaskStatus(task, 'completed')
  
        del self._tasks_merging[task.identifier]
  
        logger.debug('Completed task {0:s}.'.format(task.identifier))
docs: Completes a task.
  
      The task is complete and can be removed from the task manager.
  
      Args:
        task (Task): task.
  
      Raises:
        KeyError: if the task was not merging.