python tqdm 多个进度条

python tqdm multiple progressbars

我正在尝试编写一个使用多个线程来完成其工作的程序,所以我想通过多个进度条来显示进度,每个线程一个。我的代码看起来很像这样

import threading

def my_function(position):
    for i in tqdm(iterable=range(0,999999), position=position):
        pass

t1 = threading.Thread(target=my_function, args=(0,))
t2 = threading.Thread(target=my_function, args=(1,))

t1.start()
t2.start()

为此,我在多行中更新了进度条,如下所示

  0%|                                                                                                                                       | 0/999999 [00:00<?, ?it/s]
  6%|███████▋                                                                                                               | 64696/999999 [00:00<00:01, 645280.61it/s]
 12%|█████████████▉                                                                                                        | 117770/999999 [00:00<00:01, 605450.31it/s]
 16%|██████████████████▌                                                                                                   | 157511/999999 [00:00<00:01, 522733.58it/s]
 19%|██████████████████████▊                                                                                               | 193774/999999 [00:00<00:01, 461171.82it/s]
 24%|████████████████████████████                                                                                          | 237575/999999 [00:00<00:01, 453606.38it/s]
 30%|███████████████████████████████████▌                                                                                  | 300960/999999 [00:00<00:01, 495571.96it/s]
 35%|████████████████████████████████████████▊                                                                             | 345557/999999 [00:00<00:01, 479148.42it/s]
 40%|███████████████████████████████████████████████▋                                                                      | 404579/999999 [00:00<00:01, 507452.54it/s]
 45%|█████████████████████████████████████████████████████▌                                                                | 453429/999999 [00:00<00:01, 449045.09it/s]
 50%|██████████████████████████████████████████████████████████▊                                                           | 498244/999999 [00:01<00:01, 393065.80it/s]
 54%|███████████████████████████████████████████████████████████████▌                                                      | 538749/999999 [00:01<00:01, 396201.48it/s]
 58%|████████████████████████████████████████████████████████████████████▎                                                 | 579214/999999 [00:01<00:01, 398383.58it/s]
 62%|█████████████████████████████████████████████████████████████████████████                                             | 619647/999999 [00:01<00:00, 382102.28it/s]
 66%|█████████████████████████████████████████████████████████████████████████████▋                                        | 658415/999999 [00:01<00:00, 383456.33it/s]
 71%|███████████████████████████████████████████████████████████████████████████████████▎                                  | 706298/999999 [00:01<00:00, 407520.86it/s]
 75%|████████████████████████████████████████████████████████████████████████████████████████▏                             | 747737/999999 [00:01<00:00, 368022.06it/s]
 79%|████████████████████████████████████████████████████████████████████████████████████████████▋                         | 785749/999999 [00:01<00:00, 354975.84it/s]
 83%|██████████████████████████████████████████████████████████████████████████████████████████████████▎                   | 833386/999999 [00:01<00:00, 384078.11it/s]
 87%|███████████████████████████████████████████████████████████████████████████████████████████████████████               | 873912/999999 [00:02<00:00, 389926.98it/s]
 95%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████▋      | 946265/999999 [00:02<00:00, 452289.51it/s]
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 999999/999999 [00:02<00:00, 442573.76it/s]
100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 999999/999999 [00:02<00:00, 443857.74it/s]

我正在 windows 使用 python 3.7.3 和最新版本的 tqdm。我是 python 编码的新手,因此非常感谢您的帮助,并提前致谢。

我自己找到了解决方案,我正在浏览 tqdm(link) 的文档,发现 windows 机器需要 colorama 才能正常工作nested/multiple 条。

一次,我安装了它,程序开始运行良好。

添加描述可以

tqdm(iterable=range(0,999999), position=position, desc="description test")