progressbars#
- class progressbars(n=1, total=1, label=None, leave=False, **kwargs)[source]#
Bases:
prettyobj
Create multiple progress bars
Useful for tracking the progress of multiple long-running tasks. Unlike regular
tqdm
instances, this uses a pickable version so it can be used directly in multiprocessing instances.- Parameters:
Note: bars are supposed to update in-place, but may appear on separate lines instead if not run in the terminal (e.g. if run in IPython environments like Spyder or Jupyter).
Example:
import sciris as sc import random def run_sim(index, ndays, pbs): for i in range(ndays): val = random.random() sc.timedsleep(val*5/ndays) pbs.update(index) # Update this progress bar based on the index return nsims = 5 ndays = 365 # Create progress bars pbs = sc.progressbars(nsims, total=ndays, label='Sim') # Run tasks sc.parallelize(run_sim, iterarg=range(nsims), ndays=ndays, pbs=pbs) # Produces output like: # Sim 0: 39%|███████████████████████████▊ | 143/365 [00:01<00:01, 137.17it/s] # Sim 1: 42%|████████████████████████████▉ | 154/365 [00:01<00:01, 148.70it/s] # Sim 2: 45%|████████████████████████████████ | 165/365 [00:01<00:01, 144.19it/s] # Sim 3: 44%|███████████████████████████████ | 160/365 [00:01<00:01, 151.22it/s] # Sim 4: 42%|████████████████████████████▏ | 145/365 [00:01<00:01, 136.75it/s]
New in version 3.0.0.
Methods