use flush=True for print statements

This commit is contained in:
Max Erenberg 2022-01-06 12:51:04 -05:00
parent c30c555782
commit 0d89453062
1 changed files with 11 additions and 5 deletions

16
main.py
View File

@ -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')