code: def _find_ancestor(self, task_spec):
          
          if self.parent is None:
              return self
          if self.parent.task_spec == task_spec:
              return self.parent
          return self.parent._find_ancestor(task_spec)
docs: Returns the ancestor that has the given task spec assigned.
          If no such ancestor was found, the root task is returned.
  
          :type  task_spec: TaskSpec
          :param task_spec: The wanted task spec.
          :rtype:  Task
          :returns: The ancestor.