diff --git a/server/montytest/api.py b/server/montytest/api.py index 10768ef2..32afcd66 100644 --- a/server/montytest/api.py +++ b/server/montytest/api.py @@ -34,7 +34,7 @@ according to the route/URL mapping defined in `__init__.py`. """ -WORKER_VERSION = 20 +WORKER_VERSION = 21 @exception_view_config(HTTPException) diff --git a/worker/games.py b/worker/games.py index 73c512e9..32a8e007 100644 --- a/worker/games.py +++ b/worker/games.py @@ -1519,27 +1519,40 @@ def run_datagen_games( close_fds=not IS_WINDOWS, ) as p: try: + # Wait for the process to complete + print("Waiting for datagen to finish ... ", flush=True) + p.wait(timeout=FASTCHESS_KILL_TIMEOUT) + + if p.returncode != 0: + print( + f"Datagen process exited with code {p.returncode}. Removing binpack.", + flush=True, + ) + if games_file.exists(): + games_file.unlink() + raise WorkerException( + f"Datagen process exited with non-zero return code: {p.returncode}" + ) + + # Call parse_datagen_output only if process succeeded parse_datagen_output(p, tc_factor, result, remote, current_state) - except: + except subprocess.TimeoutExpired: + print("timeout", flush=True) + kill_process(p) + raise WorkerException("Datagen process timed out and was killed.") + except Exception: # Remove the binpack on exception print("Removing binpack", flush=True) if games_file.exists(): games_file.unlink() + else: + print("Datagen finished", flush=True) finally: - # We nicely ask cutechess-cli to stop. + # We nicely ask the monty datagen process to stop. try: send_sigint(p) except Exception as e: print("\nException in send_sigint:\n", e, sep="", file=sys.stderr) - # now wait... - print("\nWaiting for datagen to finish ... ", end="", flush=True) - try: - p.wait(timeout=FASTCHESS_KILL_TIMEOUT) - except subprocess.TimeoutExpired: - print("timeout", flush=True) - kill_process(p) - else: - print("done", flush=True) except (OSError, subprocess.SubprocessError) as e: print( "Exception starting datagen:\n", diff --git a/worker/sri.txt b/worker/sri.txt index e84c8d3a..d6f5c5dc 100644 --- a/worker/sri.txt +++ b/worker/sri.txt @@ -1 +1 @@ -{"__version": 20, "updater.py": "gSJX/HbsPwsZnUZaFbAgF0zwWPWXv+LEw9jBhJkxFOrCH9CZS0+4U4nE2fJdeNze", "worker.py": "VgVVa7f6bdHWJU/uKVcAGApcegP/fZwgV45PLSbfGTHUmc66F51hGbGBZZRvhRMM", "games.py": "jdCHJDCixQ9Fa138HXoUcOvvHEAHO7BWq/3XUmr0GYHQ/zlRYyjuSueEQPxkMTg9"} +{"__version": 21, "updater.py": "gSJX/HbsPwsZnUZaFbAgF0zwWPWXv+LEw9jBhJkxFOrCH9CZS0+4U4nE2fJdeNze", "worker.py": "n3cgpMhYBEOQVvXl+NNEv6YCsbWqbH0jqiDaI5g0yoCot8fEbThrenDdYNMkI+oq", "games.py": "MyB/5iO/R0PEXQOB+ZhACzieuTTRnuGE3gbzvul35gewqG/t58EztU0fY0FYCzOA"} diff --git a/worker/worker.py b/worker/worker.py index 70731f06..e7aac5d0 100644 --- a/worker/worker.py +++ b/worker/worker.py @@ -69,7 +69,7 @@ MIN_CARGO_MAJOR = 1 MIN_CARGO_MINOR = 77 -WORKER_VERSION = 20 +WORKER_VERSION = 21 FILE_LIST = ["updater.py", "worker.py", "games.py"] HTTP_TIMEOUT = 30.0 INITIAL_RETRY_TIME = 15.0