def _find_ancestor(self, task_spec):
if self.parent is None:<EOL><INDENT>return self<EOL><DEDENT>if self.parent.task_spec == task_spec:<EOL><INDENT>return self.parent<EOL><DEDENT>return self.parent._find_ancestor(task_spec)<EOL>
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.