print tqdm progress bar only in interactive tty (as opposed to cronjob)

This commit is contained in:
Matthäus Wander
2021-08-22 10:31:09 +02:00
parent 2ea89c60b9
commit d335d594f5
+10 -5
View File
@@ -13,6 +13,7 @@ import json
from ssl import CERT_NONE, create_default_context
from multiprocessing import Pool, Value
from itertools import repeat
import sys
import time
from tqdm import tqdm
@@ -626,11 +627,15 @@ def _main():
repeat(opts.offline),
repeat(opts.n_procs >= 1)),
opts.chunk_size)
pbar = tqdm(total=len(file_paths))
while not results.ready():
pbar.update(counter.value - pbar.n)
time.sleep(0.1)
pbar.close()
if sys.stdout.isatty():
pbar = tqdm(total=len(file_paths))
while not results.ready():
pbar.update(counter.value - pbar.n)
time.sleep(0.1)
pbar.close()
else:
while not results.ready():
time.sleep(0.1)
results = results.get()
pool.close()
pool.join()