don't crash on stalls

This commit is contained in:
xenofem 2021-11-22 20:10:58 -05:00
parent af7bb62a13
commit 465fb2ba5d

View file

@ -3,6 +3,7 @@
import argparse import argparse
import datetime import datetime
import subprocess import subprocess
import sys
import time import time
WINDOW_SIZE = 100 WINDOW_SIZE = 100
@ -72,18 +73,19 @@ while True:
rate = (current - samples[0])/((len(samples)-1)*args.interval) rate = (current - samples[0])/((len(samples)-1)*args.interval)
print('\033[2K\r', end='') print('\033[2K\r', end='')
print('{} - {}/s'.format(display_value(current), display_value(rate)), end='', flush=True) print('{} - {}/s'.format(display_value(current), display_value(rate)), end='')
if final: if final:
fraction = current / final fraction = current / final
value_remaining = final - current value_remaining = final - current
print(' - {} total - {:.1f}% complete'.format(display_value(final), 100*fraction), end='')
if rate > 0:
time_remaining = datetime.timedelta(seconds=(value_remaining / rate)) time_remaining = datetime.timedelta(seconds=(value_remaining / rate))
eta = datetime.datetime.now() + time_remaining eta = datetime.datetime.now() + time_remaining
print(' - {} total - {:.1f}% complete - {} remaining - ETA {}'.format( print(' - {} remaining - ETA {}'.format(
display_value(final),
100*fraction,
display_timedelta(time_remaining), display_timedelta(time_remaining),
eta.isoformat(sep=' ', timespec='minutes'), eta.isoformat(sep=' ', timespec='minutes'),
), end='', flush=True) ), end='')
sys.stdout.flush()
if final and current >= final: if final and current >= final:
print() print()