diff --git a/ia-upload-stream b/ia-upload-stream index 75c2e0b..bb5c551 100755 --- a/ia-upload-stream +++ b/ia-upload-stream @@ -112,15 +112,20 @@ def file_progress_bar(f, mode, description, size = None): wrappedFile = tqdm.utils.CallbackIOWrapper(t.update, f, mode) yield wrappedFile else: - # Simple progress bar that just prints a new line with elapsed time and size in MiB on every read or write + # Simple progress bar that just prints a new line with elapsed time and size in MiB on every read or write if it hasn't printed for at least a second processedSize = 0 startTime = time.time() + lastPrintTime = 0 def _progress(inc): - nonlocal processedSize + nonlocal processedSize, lastPrintTime processedSize += inc + now = time.time() + if now - lastPrintTime < 1: + return proc = f'{processedSize / size * 100 :.0f}%, ' if size else '' of = f' of {size / 1048576 :.2f}' if size else '' - print(f'\r{description}: {proc}{processedSize / 1048576 :.2f}{of} MiB, {time.time() - startTime :.1f} s', end = '', file = sys.stderr) + print(f'\r{description}: {proc}{processedSize / 1048576 :.2f}{of} MiB, {now - startTime :.1f} s', end = '', file = sys.stderr) + lastPrintTime = now class Wrapper: def __init__(self, wrapped): object.__setattr__(self, '_wrapped', wrapped)