def bfs(self, direction, *jobs, stop=(lambda job: False)):
    'Perform a breadth-first traversal of the DAG.'
    queue = list(jobs)
    visited = set(queue)
    while queue:
        job = queue.pop(0)
        if stop(job):
            continue
        (yield job)
        for (job_, _) in direction[job].items():
            if (not (job_ in visited)):
                queue.append(job_)
                visited.add(job_)
Perform a breadth-first traversal of the DAG.
def bfs(self, direction, *jobs, stop=(lambda job: False)):
    
    queue = list(jobs)
    visited = set(queue)
    while queue:
        job = queue.pop(0)
        if stop(job):
            continue
        (yield job)
        for (job_, _) in direction[job].items():
            if (not (job_ in visited)):
                queue.append(job_)
                visited.add(job_)