我在 ThreadPoolExecutor 中运行的函数中有一个 Tqdm。问题是每个线程的进度条在每次更新时都会重新打印。我希望这 3 个小节保持不变并根据各自的进度进行更新。 代码来自教程(例6)
我在 stackoverflow 上找到的其他示例在执行程序级别使用 Tqdm。我的 Tqdm 位于执行函数级别,我想知道是否可以这样做。
我使用 Windows10、PyCHarm 和 Python 3.9。
import time
from tqdm import tqdm
from concurrent.futures import ThreadPoolExecutor
def worker(thread_number):
for i in tqdm(range(100), desc=f'thread {thread_number}'):
time.sleep(0.05 * thread_number)
if __name__ == '__main__':
thread_list = list(range(1, 4))
with ThreadPoolExecutor() as p:
p.map(worker, thread_list)
我都试过了
from tqdm import tqdm
和
from tqdm.auto import tqdm
我想要这样: