From 1e51a9cf2ae66174a3df61ffa09accf490d957c5 Mon Sep 17 00:00:00 2001 From: huihun <781165206@qq.com> Date: Mon, 22 Apr 2024 21:12:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Btqdm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- json_feature2json.py | 2 ++ my_utils.py | 29 ++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/json_feature2json.py b/json_feature2json.py index e351eaa..8e07ee4 100644 --- a/json_feature2json.py +++ b/json_feature2json.py @@ -50,6 +50,7 @@ def addr2vec(base_file_path, index): results = list(tqdm(pool.imap_unordered(bb2vec, [item for item in feature_json]), total=len(feature_json), desc=f'{file_name} Progress:{index}/{json_files_len} ', + ascii=True, leave=False, dynamic_ncols=True, position=1)) @@ -120,6 +121,7 @@ if __name__ == '__main__': for index, json_file in tqdm(enumerate(json_files), total=len(json_files), + ascii=True, desc='Total:', position=0): if os.path.isfile(os.path.join(json_path, json_file)): diff --git a/my_utils.py b/my_utils.py index 8194626..bc25096 100644 --- a/my_utils.py +++ b/my_utils.py @@ -1,6 +1,7 @@ import logging import os import json +from tqdm import tqdm """ 日志工具 @@ -73,13 +74,6 @@ def multi_thread_order(func, args, thread_num=THREAD_FULL): return result -def multi_thread_disorder(func, thread_num=THREAD_FULL, **args): - import multiprocessing - from tqdm import tqdm - with multiprocessing.Pool(processes=thread_num) as pool: - list(tqdm(pool.imap_unordered(func, args), total=len(args))) - - def save_json(filename, data): data = json.dumps(data) # 确保路径存在 @@ -101,3 +95,24 @@ def load_json(filename): data = json.loads(file.read()) file.close() return data + + +def set_tqdm(obj_list, front_text, multiple_thread=False, *args): + """ + :param args[0]:多线程显示位置 + """ + if not multiple_thread: + return tqdm(obj_list, + total=len(obj_list), + ascii=True, + desc=front_text, + ) + else: + return tqdm(obj_list, + total=len(obj_list), + ascii=True, + desc=front_text, + position=args[0] + ) + +