From a7b8c772462d269429b4a1cc1aee4e88129c5d21 Mon Sep 17 00:00:00 2001 From: Almamu Date: Sun, 20 Apr 2025 22:48:40 +0200 Subject: [PATCH] chore: improve scripts for running the app --- tools/scripts/run.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/scripts/run.py b/tools/scripts/run.py index 844e670..5f2488b 100644 --- a/tools/scripts/run.py +++ b/tools/scripts/run.py @@ -21,11 +21,18 @@ def run_and_monitor(program, program_args=None, output_file="output.png", wait_t start_time = time.time() while time.time() - start_time < timeout: - print("Polling for file {output_file}".format(output_file=output_file)) - # Check if the file is created - if os.path.exists(output_file): + # wait for the process to die, if it did, stop the waiting already + try: + process.wait(wait_time) break - time.sleep(wait_time) + except subprocess.TimeoutExpired: + # otherwise check for the file, if it exists stop waiting + print("Polling for file {output_file}".format(output_file=output_file)) + # Check if the file is created + if os.path.exists(output_file): + # give the screenshot some time to be written properly, just in case + time.sleep(wait_time) + break else: print("Timeout reached. File not found.")