ThreadPoolExecutor 的每个线程中的 Tqdm

问题描述 投票:0回答:0

我在 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

目前Pycharm的控制台显示:

我想要这样:

python-3.x windows-10 python-multithreading threadpoolexecutor tqdm
© www.soinside.com 2019 - 2024. All rights reserved.