From 0d894530625810659d3c2920b090cf12c52280a5 Mon Sep 17 00:00:00 2001 From: Max Erenberg <> Date: Thu, 6 Jan 2022 12:51:04 -0500 Subject: [PATCH] use flush=True for print statements --- main.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index c1161cc..b7c6a4e 100644 --- a/main.py +++ b/main.py @@ -12,6 +12,12 @@ from projects import * import json +def safe_print(*args, **kwargs): + # When run with 'chronic' and 'timeout', stdout gets suppressed + # due to buffering. Make sure to always flush the output. + print(*args, **kwargs, flush=True) + + if __name__ == "__main__": exit_code = 0 @@ -32,9 +38,9 @@ if __name__ == "__main__": checker_result = project_class.check(data, project, current_time) if project in ["CPAN", "ubuntu", "ubuntu_releases", "manjaro", "mxlinux", "cran", "ctan", "gentooportage"]: if checker_result: - print(f"Success: {project} up-to-date") + safe_print(f"Success: {project} up-to-date") else: - print(f"Failure: {project} out-of-sync") + safe_print(f"Failure: {project} out-of-sync") # Exit with non-zero status if any of the projects are not up-to-date exit_code = 1 @@ -45,14 +51,14 @@ if __name__ == "__main__": data[project]["out_of_sync_since"] = current_time elif current_time - data[project]["out_of_sync_since"] \ > data[project]["out_of_sync_interval"]: - print(f"Failure: {project} out-of-sync") + safe_print(f"Failure: {project} out-of-sync") # Exit with non-zero status if any of the projects are not up-to-date exit_code = 1 continue - print(f"Success: {project} up-to-date") + safe_print(f"Success: {project} up-to-date") except requests.exceptions.RequestException as err: - print(f"Error: {project}\n{err}") + safe_print(f"Error: {project}\n{err}") with open(data_file, "w", encoding="utf-8") as file: json.dump(data, file, indent='\t')