From 0978f3b4667e81ab2969581a6ddc244b17837855 Mon Sep 17 00:00:00 2001 From: Nicolas Mendes Date: Mon, 21 Feb 2022 00:43:35 -0300 Subject: [PATCH] Optimizing performance --- SLN.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SLN.py b/SLN.py index 6f10c9c..7befdd2 100644 --- a/SLN.py +++ b/SLN.py @@ -42,6 +42,8 @@ if not VERSION_PATH.exists(): with open(f"{VERSION_PATH}", "w") as version_file: version_file.write(json.dumps({"currentVersion": "v1.0.0 - Release"})) + # close + version_file.close() with open(f"{VERSION_PATH}", "r+") as version_file: version_data = json.load(version_file) @@ -54,6 +56,7 @@ version_file.write(json.dumps({"currentVersion": "v1.0.0 - Release"})) current_version = version_data["currentVersion"] + version_file.close() def relative_to_logs(path: str) -> Path: @@ -152,6 +155,7 @@ def log_routine(log: str, time_needed: bool = True, hide_pid: bool = True): # append log_header to the file. with open(f"{relative_to_logs(f'{file_log_name}.log')}", "a") as log_file: log_file.write(log_header) + log_file.close() # if the first line of {file_log_name}.log is different from current_version with open(f"{relative_to_logs(f'{file_log_name}.log')}") as check_ver: @@ -165,6 +169,7 @@ def log_routine(log: str, time_needed: bool = True, hide_pid: bool = True): log_file.write( "\n\n[NOTICE] Log file has been deleted or cleaned.\n" ) + log_file.close() else: # Delete everything inside the file and append log_header. with open( @@ -174,6 +179,7 @@ def log_routine(log: str, time_needed: bool = True, hide_pid: bool = True): log_file.write( f"\n\n[NOTICE] PROGRAM HAS BEEN UPDATED TO {current_version}!\n" ) + log_file.close() # if the file exceeds 1000 lines, delete everything and append log_header to the file. with open(f"{relative_to_logs(f'{file_log_name}.log')}", "r") as log_file: @@ -207,3 +213,4 @@ def log_routine(log: str, time_needed: bool = True, hide_pid: bool = True): if __name__ == "__main__": print(__copyright__) + exit()