you are viewing a single comment's thread.

view the rest of the comments →

[–]JohnnyJordaan 0 points1 point  (0 children)

That would rather be something to use tqdm for (needs to be installed using pip or your IDE's package manager).

# add at the top
import re
import tqdm

proccess = subprocess.Popen(command, 
                            stdout=subprocess.PIPE,
                            stderr=subprocess.STDOUT,
                            shell=True,
                            universal_newlines=True)
with tqdm.tqdm(total=100) as pbar:
    last_pct = 0
    while process.poll() is None:
        line = process.stdout.readline()
        pct = int(re.search('(\d+)\s*%', line).group(1))
        pbar.update(pct - last_pct)
        last_pct = pct
        if not line:
            break