You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
luscenje_struktur/luscenje_struktur/progress_bar.py

35 lines
868 B

import time
import logging
5 years ago
try:
from tqdm import tqdm
except ImportError:
tqdm = None
REPORT_ON = 0.3
5 years ago
class Progress:
def __call__(self, iterable, description, total=None):
5 years ago
if tqdm is None:
try:
total = len(iterable)
except TypeError:
total = -1
start_time = time.time()
last_report = start_time - REPORT_ON
for n, el in enumerate(iterable):
now = time.time()
if now - last_report > REPORT_ON:
logging.info("\r{}: {}/{}".format(description, n, total), end="")
last_report = now
5 years ago
yield el
logging.info(" -> {}".format(time.time() - start_time))
5 years ago
else:
yield from tqdm(iterable, desc=description, total=total)
5 years ago
progress = Progress()