'Mark Node as Failed under graphlib TopologicalSorter

From graphlib.TopologicalSorter, I can process nodes from a graph in parallel via:

topological_sorter = TopologicalSorter()
topological_sorter.prepare()

while topological_sorter.is_active():
    for node in topological_sorter.get_ready():
        task_queue.put(node)

    node = finalized_tasks_queue.get()
    topological_sorter.done(node)

In my actual usecase, I have the topological_sorter.done conditioned on the status code of node like so:

if node.status_code == 0:
    topological_sorter.done(node)

0 represents success, and non-0 represents failure.

Given a node in a graph that depends on many other nodes, in the event that one of the dependees has a non-0 status code, I'd like topological_sorter.is_active() to return False (indicating that processing has went as far as possible).

However, the current behavior is that my while look will keep iterating, waiting for the last done() for a node with the non-0 status code to execute. Of course, that will never happen.

Is there anyway to signal to TopologicalSorter that a node failed? Each node would then eventually become the subject of a done call (processing succeeded), a fail-equivalent call (processing failed), or no call at all (processing went on forever).



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source