如何使用tqdm通过循环构建多个进程条?

How to build multiple process bars through a loop by using tqdm?

我想用tqdm在外循环的每次迭代中做一个process bar,但是失败了

import numpy as np
from tqdm import tqdm

for i in range(10):
   pbar = tqdm(total=200)
   for j in range(200):
      ...
      pbar.update(j+1)
   pbar.close()

起初,这段代码运行良好。

The result of first iteration

外循环第一次迭代后,进程条消失,继续迭代

The result after first ieteration 为什么第一个循环没有创建新的流程栏?如何解决这个问题?

您不需要更新 pbar

import numpy as np
from tqdm import tqdm
import time

for i in tqdm(range(10)):
    for j in tqdm(range(200)):
        # do something here
        time.sleep(0.01)