def DFS_visit(G, coloring, v):
    """A recursive generator implementation of a depth-first search visitor.

    Please note that as a recursive function, it may exhaust Python's
    stack. Consider using NetworkX or PADS instead. Results are
    produced incrementally, a nice benefit of using a generator.
    """
    
    if v in coloring:
        return
        
    yield v
    coloring[v] = GRAY

    for w in adjacent(G, v):
        if w not in coloring:
            for descendant in DFS_visit(G, coloring, w):
                yield descendant
    coloring[v] = BLACK
A recursive generator implementation of a depth-first search visitor.

    Please note that as a recursive function, it may exhaust Python's
    stack. Consider using NetworkX or PADS instead. Results are
    produced incrementally, a nice benefit of using a generator.
    
recipes/Python/498260_Examples_algorithm_compositiobserver_pattern/recipe-498260.py