1010from senzing import SzBadInputError , SzError , SzRetryableError , SzUnrecoverableError
1111from senzing_core import SzAbstractFactoryCore
1212
13- SETTINGS = os .getenv ("SENZING_ENGINE_CONFIGURATION_JSON" , "{}" )
1413INPUT_FILE = Path ("../../resources/data/load-500.jsonl" ).resolve ()
1514INSTANCE_NAME = Path (__file__ ).stem
15+ SETTINGS = os .getenv ("SENZING_ENGINE_CONFIGURATION_JSON" , "{}" )
1616
1717
1818def mock_logger (level , error , error_record = None ):
@@ -40,13 +40,14 @@ def engine_stats(engine):
4040
4141def futures_add (engine , input_file ):
4242 success_recs = 0
43+ shutdown = False
4344 error_recs = 0
4445
45- with open (input_file , "r" , encoding = "utf-8" ) as file :
46+ with open (input_file , "r" , encoding = "utf-8" ) as in_file :
4647 with concurrent .futures .ThreadPoolExecutor () as executor :
4748 futures = {
4849 executor .submit (add_record , engine , record ): record
49- for record in itertools .islice (file , executor ._max_workers )
50+ for record in itertools .islice (in_file , executor ._max_workers )
5051 }
5152
5253 while futures :
@@ -61,7 +62,7 @@ def futures_add(engine, input_file):
6162 mock_logger ("WARN" , err , futures [f ])
6263 error_recs += 1
6364 except (SzUnrecoverableError , SzError ) as err :
64- mock_logger ( "CRITICAL" , err , futures [ f ])
65+ shutdown = True
6566 raise err
6667 else :
6768 success_recs += 1
@@ -71,7 +72,7 @@ def futures_add(engine, input_file):
7172 if success_recs % 200 == 0 :
7273 engine_stats (engine )
7374 finally :
74- if record := file .readline ():
75+ if not shutdown and ( record := in_file .readline () ):
7576 futures [executor .submit (add_record , engine , record )] = record
7677
7778 del futures [f ]
0 commit comments