1414from framework .oracles .impl .JunctionLaneChangeOracle import JunctionLaneChangeOracle
1515
1616from typing import List , Tuple
17+ import time
1718
1819
1920class RecordAnalyzer :
@@ -23,11 +24,15 @@ class RecordAnalyzer:
2324 :param str record_path: filename of the record
2425 """
2526 record_path : str
27+ analyzed : bool
28+ MAX_RETRY = 3 # times
29+ RETRY_DELAY = 2 # seconds
2630
2731 def __init__ (self , record_path : str ) -> None :
2832 self .oracle_manager = OracleManager ()
2933 self .record_path = record_path
3034 self .register_oracles ()
35+ self .analyzed = False
3136
3237 def register_oracles (self ):
3338 """
@@ -56,10 +61,22 @@ def analyze(self) -> List[Tuple]:
5661 :returns: list of violations
5762 :rtype: List[Tuple]
5863 """
59- record = Record (self .record_path )
60- for topic , message , t in record .read_messages ():
61- self .oracle_manager .on_new_message (topic , message , t )
62- return self .get_results ()
64+ trial = 1
65+ while trial <= RecordAnalyzer .MAX_RETRY :
66+ try :
67+ record = Record (self .record_path )
68+ for topic , message , t in record .read_messages ():
69+ self .oracle_manager .on_new_message (topic , message , t )
70+ self .analyzed = True
71+ return self .get_results ()
72+ except AttributeError :
73+ time .sleep (2 )
74+ trial += 1
75+ except FileNotFoundError :
76+ time .sleep (2 )
77+ trial += 1
78+ return list ()
79+
6380
6481 def get_results (self ) -> List [Tuple ]:
6582 """
@@ -68,4 +85,6 @@ def get_results(self) -> List[Tuple]:
6885 :returns: list of violations
6986 :rtype: List[Tuple]
7087 """
88+ if not self .analyzed :
89+ return list ()
7190 return self .oracle_manager .get_results ()
0 commit comments