【问题标题】:Is there some way to use tqdm with simpy.Environment.run()?有没有办法将 tqdm 与 simpy.Environment.run() 一起使用?
【发布时间】:2021-08-18 11:30:14
【问题描述】:

你好,我只是想知道是否存在一些神奇的方法,使用 tqdm 来预测多长时间 它需要一个环境的整个简单模拟。

我尝试做类似的事情:

from tqdm.auto import tqdm

tqdm(env.run(until=100))

但是没有效果。有人知道这是否可能吗?

【问题讨论】:

    标签: python tqdm simpy


    【解决方案1】:

    我对 tqdm 不是很熟悉,但我认为您需要使用它来包装迭代器,而 env.run(until=100) 不是迭代器。但是,您可以在不断增加 until 参数的步骤中运行 sim。这是一个例子

    """
    quick test of tqdm progress bar with a sim
    
    Programer Michael R. Gibbs
    """
    
    import simpy
    from tqdm import tqdm 
    import time
    
    
    def task(env):
        """
        dummy task to sim
        """
        while True:
            yield env.timeout(1)
    
    # create sim
    env = simpy.RealtimeEnvironment(factor=.1)
    env.process(task(env))
    
    # run sim in steps
    for t in tqdm(range(10,101,5)):
        env.run(until=t)
    

    【讨论】:

      猜你喜欢
      • 2021-10-01
      • 2018-03-15
      • 2016-11-01
      • 1970-01-01
      • 2018-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多