def _dfs(job):
    'Inner function for DFS traversal.'
    if stop(job):
        return
    if (not post):
        (yield job)
    for job_ in direction[job]:
        if (not (job_ in visited)):
            visited.add(job_)
            for j in _dfs(job_):
                (yield j)
    if post:
        (yield job)
Inner function for DFS traversal.
def _dfs(job):
    
    if stop(job):
        return
    if (not post):
        (yield job)
    for job_ in direction[job]:
        if (not (job_ in visited)):
            visited.add(job_)
            for j in _dfs(job_):
                (yield j)
    if post:
        (yield job)