1
0
mirror of https://github.com/gryf/coach.git synced 2025-12-17 11:10:20 +01:00

added a simple progress bar implementation

This commit is contained in:
itaicaspi-intel
2018-09-13 14:21:38 +03:00
parent fa79d8d365
commit 607ef17431
3 changed files with 34 additions and 10 deletions

View File

@@ -20,6 +20,7 @@ import inspect
import json
import os
import signal
import sys
import threading
import time
from multiprocessing import Manager
@@ -548,4 +549,24 @@ class ReaderWriterLock(object):
def release_writing(self):
self.num_readers_lock.acquire()
self.num_readers -= 1
self.num_readers_lock.release()
self.num_readers_lock.release()
class ProgressBar(object):
def __init__(self, max_value):
self.start_time = time.time()
self.max_value = max_value
self.current_value = 0
def update(self, current_value):
self.current_value = current_value
percentage = int((100 * current_value) / self.max_value)
sys.stdout.write("\rProgress: ({}/{}) Time: {} sec {}%|{}{}| "
.format(current_value, self.max_value,
round(time.time() - self.start_time, 2),
percentage, '#' * int(percentage / 10),
' ' * (10 - int(percentage / 10))))
sys.stdout.flush()
def close(self):
print("")