改进tqdm
This commit is contained in:
parent
b2b6a2b7a6
commit
1e51a9cf2a
@ -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)):
|
||||
|
29
my_utils.py
29
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]
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user