Gets the descendants using a graph structure, a queue, and a buffer.
def get_descendants(node):
unexplored = deque([node])
while unexplored:
node = unexplored.popleft()
yield node
children = node.children
for child in children:
unexplored.append(child)