From 2e599db953adb17071a1077143f7a149a66b99ff Mon Sep 17 00:00:00 2001 From: sunyiming Date: Wed, 13 Mar 2024 09:16:50 +0000 Subject: [PATCH 1/2] update debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py. Signed-off-by: sunyiming --- .../api_accuracy_checker/dump/info_dump.py | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py b/debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py index e90b1f988..9c4af2e84 100644 --- a/debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py +++ b/debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py @@ -38,29 +38,26 @@ def write_api_info_json(api_info): def write_json(file_path, data, indent=None): check_file_or_directory_path(os.path.dirname(file_path), True) - proc_lock.acquire() - lock.acquire() - if not os.path.exists(file_path): - with FileOpen(file_path, 'w') as f: - f.write("{\n}") - change_mode(file_path, FileCheckConst.DATA_FILE_AUTHORITY) - with FileOpen(file_path, 'a+') as f: + with lock, FileOpen(file_path, 'a+') as f: fcntl.flock(f, fcntl.LOCK_EX) try: f.seek(0, os.SEEK_END) - f.seek(f.tell() - 1, os.SEEK_SET) - f.truncate() - if f.tell() > 3: - f.seek(f.tell() - 1, os.SEEK_SET) + current_position = f.tell() + if current_position > 0: + f.seek(current_position - 1, os.SEEK_SET) f.truncate() - f.write(',\n') - f.write(json.dumps(data, indent=indent)[1:-1] + '\n}') + if f.tell() > 3: + f.seek(f.tell() - 1, os.SEEK_SET) + f.truncate() + f.write(',\n') + f.write(json.dumps(data, indent=indent)[1:-1] + '\n}') + else: + change_mode(file_path, FileCheckConst.DATA_FILE_AUTHORITY) + f.write('{\n' + json.dumps(data, indent=indent)[1:] + '\n') except Exception as e: raise ValueError(f"Json save failed:{e}") from e finally: fcntl.flock(f, fcntl.LOCK_UN) - lock.release() - proc_lock.release() def initialize_output_json(): -- Gitee From de4742b1e0e45d6eb5de7e5ce1dbd0f016b050da Mon Sep 17 00:00:00 2001 From: sunyiming Date: Fri, 15 Mar 2024 02:04:50 +0000 Subject: [PATCH 2/2] update debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py. Signed-off-by: sunyiming --- debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py b/debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py index 9c4af2e84..c73058e4f 100644 --- a/debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py +++ b/debug/accuracy_tools/api_accuracy_checker/dump/info_dump.py @@ -38,7 +38,7 @@ def write_api_info_json(api_info): def write_json(file_path, data, indent=None): check_file_or_directory_path(os.path.dirname(file_path), True) - with lock, FileOpen(file_path, 'a+') as f: + with proc_lock, lock, FileOpen(file_path, 'a+') as f: fcntl.flock(f, fcntl.LOCK_EX) try: f.seek(0, os.SEEK_END) -- Gitee