From d335d594f5ff719fe007f78c996ba959f2eea52c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matth=C3=A4us=20Wander?= Date: Sun, 22 Aug 2021 10:31:09 +0200 Subject: [PATCH] print tqdm progress bar only in interactive tty (as opposed to cronjob) --- parsedmarc/cli.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/parsedmarc/cli.py b/parsedmarc/cli.py index be2026a..81aa175 100644 --- a/parsedmarc/cli.py +++ b/parsedmarc/cli.py @@ -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()