def METHOD_NAME(task, history):
    current = history[:]
    current.append(task)
    if isinstance(task, Join):
        if task in history:
            msg = "Found loop with '%s': %s then '%s' again" % (
                task.name, '->'.join([p.name for p in history]),
                task.name)
            raise Exception(msg)
        for predecessor in task.inputs:
            METHOD_NAME(predecessor, current)
    for parent in task.inputs:
        METHOD_NAME(parent, current)