Python Graphlib Module done(*nodes)














































Python Graphlib Module done(*nodes)



In the previous article, we have seen get_ready( ) method in Graphlib 

module.



In this article, we discuss about done(*nodes) in Graphlib module.


done(*nodes):

*This method marks a set of nodes returned   by TopologicalSorter.get_ready( )  as processed ,unlocking an   sucessor  of each node in nodes being returned in the future by a call   to TopologicalSorter.get_ready( )


codesnippet:

from graphlib import TopologicalSorter
  
graph = {1 : {6},2: {3}, 3: {1}, 4: {0, 1}, 5: {0, 2}}
t=TopologicalSorter(graph)
t.prepare()
r=t.get_ready( )
t.done(*r)


->It will raises ValueError-
  *if any node in nodes has already been marked as     processed by a   previous call to this method.

 *If a node was not added to the graph by using    TopologicalSorter.add( ) 

 *If called without calling prepare( ) or if node has not   yet returned     by  get_ready() 


Example:

from graphlib import TopologicalSorter
  
graph = {1 : {6},2: {3}, 3: {1}, 4: {0, 1}, 5: {0, 2}}
t=TopologicalSorter(graph)

r=t.get_ready()

t.done(*r)

Error:
Traceback (most recent call last):
  File "C:\Users\findm\AppData\Local\Programs\Python\Python39\graphlib.py", line 8, in <module>
    r=t.get_ready()
  File "C:\Users\findm\AppData\Local\Programs\Python\Python39\lib\graphlib.py", line 117, in get_ready
    raise ValueError("prepare() must be called first")
ValueError: prepare() must be called first




Comments