From c5522e8c7217100347ccd8e23fda93bd2db3f48f Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Wed, 28 Aug 2024 02:22:54 +0300 Subject: [PATCH] add timeout --- logs_parser.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/logs_parser.py b/logs_parser.py index 558ff6f..2bf4e8c 100644 --- a/logs_parser.py +++ b/logs_parser.py @@ -10,7 +10,7 @@ def is_json(myjson): return False return True -def parse_logs(): +def parse_logs(timeout): start_time = time.time() while True: unsuccessful_attempts = 0 @@ -55,15 +55,19 @@ def parse_logs(): print("Sleeping before next log request...", flush=True) time.sleep(30) - if time.time() - start_time > 30 * 60: - print("Timeout reached: 30 minutes elapsed without success.", flush=True) - return False, "Timeout reached: 30 minutes elapsed without success." + if time.time() - start_time > timeout: + print(f"Timeout reached: {timeout} minutes elapsed without success.", flush=True) + return False, f"Timeout reached: {timeout} minutes elapsed without success." return False, "No Success" if __name__ == "__main__": - print("Parsing logs...") - result = parse_logs() + print("Parsing logs...") + if len(sys.argv) > 1: + timeout = eval(sys.argv[1]) + else: + timeout = 30 + result = parse_logs(timeout) print(result[1]) if result[0] == False: print("Exiting 1...")