def level_bfs(self, direction, *jobs, stop=(lambda job: False)):
    'Perform a breadth-first traversal of the DAG, but also yield the\n        level together with each job.'
    queue = [(job, 0) for job in jobs]
    visited = set(jobs)
    while queue:
        (job, level) = queue.pop(0)
        if stop(job):
            continue
        (yield (level, job))
        level += 1
        for (job_, _) in direction[job].items():
            if (not (job_ in visited)):
                queue.append((job_, level))
                visited.add(job_)
Perform a breadth-first traversal of the DAG, but also yield the
level together with each job.
def level_bfs(self, direction, *jobs, stop=(lambda job: False)):
    'Perform a breadth-first traversal of the DAG, but also yield the\n        level together with each job.'
    queue = [(job, 0) for job in jobs]
    visited = set(jobs)
    while queue:
        (job, level) = queue.pop(0)
        if stop(job):
            continue
        (yield (level, job))
        level += 1
        for (job_, _) in direction[job].items():
            if (not (job_ in visited)):
                queue.append((job_, level))
                visited.add(job_)