Python Graphlib Module is_active( )














































Python Graphlib Module is_active( )



In the previous article, we have discussed about prepare( ) method 


In this article, we are going to discuss more methods in Graphlib module.


is_active( ):
-> This method returns true if more progress can be made and False   otherwise.

-> Progress can be made if cycles do not block the resolution.
-> Progress can also be made if there are still nodes ready that have   not returned by TopologicalSorter.get_ready( ) or the number of nodes   marked TopologicalSorter.done( ) is less than the number that have   been returned by TopologicalSorter.get_ready( ). 

Example:
from graphlib import TopologicalSorter
  
toposort = TopologicalSorter()
  
toposort.add(7,8,2)
toposort.add(9,5,6)
toposort.add(1,3,4)
toposort.prepare()
if toposort.is_active():
    print("Progress can be made")
else:
    print("Progress cannot be made")
Output:
Progress can be made


->It raises ValueError if prepare( ) funtion is not called previously.

from graphlib import TopologicalSorter
  
toposort = TopologicalSorter()
  
toposort.add(3,2,4)

toposort.is_active()
Output:
Traceback (most recent call last):
  File "C:\Users\findm\AppData\Local\Programs\Python\Python39\graphlib.py", line 8, in <module>
    toposort.is_active()
  File "C:\Users\findm\AppData\Local\Programs\Python\Python39\lib\graphlib.py", line 143, in is_active
    raise ValueError("prepare() must be called first")
ValueError: prepare() must be called first

Comments