I'm currenty working on a progress bar for another project. I pretty much have everything done and working as intended.
However, i am having an issue, where i can't have two (or more) bars displaying simultaneously. The second one always seems to overwrite the first.
Here's the code (excuse my crappy coding skills):
Progress Bar Class:
import sys
class ProgressBar():
full_size = 100
standard = 50
small = 25
def __init__(self, pretext, length=50, total=100):
self.pretext = pretext
self.length = length
self.total = total
def update_bar(self, fill_amount):
real_fill_amount = int(self.length * fill_amount / self.total)
sys.stdout.write("\r%s |%s%s| %s" % (self.pretext,
"█" * real_fill_amount,
"░" * (self.length - real_fill_amount),
str(fill_amount) + "%"))
sys.stdout.flush()
Example code (CPU and Memory Usage Meter):
from pout_progressbar import ProgressBar
import psutil
import time
bar1 = ProgressBar("CPU Usage", length=ProgressBar.standard, total=100)
bar2 = ProgressBar("Memory Usage", length=ProgressBar.standard, total=100)
while True:
bar1.update_bar(int(psutil.cpu_percent(interval=1)))
bar2.update_bar(int(psutil.virtual_memory().percent))
time.sleep(0.5)
Note: pout_progressbar is the filename of the ProgressBar module.
In the example script, two bars are supposed to be showing, but only the second one is showing.
Is there any way i can fix this ?
Thanks in advance.