In [1]:
%load_ext watermark
%watermark -v -d -u
In [2]:
import pyprind
In [3]:
n = 150000
bar = pyprind.ProgBar(n)
for i in range(n):
# do some computation
bar.update()
Note: the Percentage indicator is significantly slower due to background computation.
Thus, it is recommended for tasks with less iterations but longer computational time per iteration.
In [4]:
n = 1500
perc = pyprind.ProgPercent(n)
for i in range(n):
# do some computation
perc.update()
Alternatively, you can use the progress bar and percentage indicators as generators.
In [5]:
for i in pyprind.prog_bar(range(n)):
# do something
pass
In [7]:
for i in pyprind.prog_percent(range(n)):
# do something
pass
Simply print()
the tracking object after the tracking has completed.
In [4]:
n = 150000
bar = pyprind.ProgBar(n)
for i in range(n):
# do some computation
bar.update()
print(bar)
In [5]:
n = 150000
bar = pyprind.ProgBar(n, monitor=True, title='Job_1')
for i in range(n):
# do some computation
bar.update()
# print report for future reference
print(bar)
monitor
(bool
): default False. Monitors CPU and memory usage if True
(requires the psutil
package).
In [6]:
n = 150000
bar = pyprind.ProgBar(n, monitor=True)
for i in range(n):
# do some computation
bar.update()
print(bar)
In [7]:
n = 1500
perc = pyprind.ProgPercent(n, monitor=True)
for i in range(n):
# do some computation
perc.update()
print(perc)
title
(str
): default ''. A title for the progress bar
In [8]:
n = 150000
bar = pyprind.ProgBar(n, title='My 1st Progress Bar')
for i in range(n):
# do some computation
bar.update()
In [9]:
n = 1500
perc = pyprind.ProgPercent(n, title='My 1st Percent Tracker')
for i in range(n):
# do some computation
perc.update()
width
(int
): default 30. Sets the progress bar width in characters.
In [10]:
n = 150000
bar = pyprind.ProgBar(n, width=10)
for i in range(n):
# do some computation
bar.update()
bar = pyprind.ProgBar(n, width=70)
for i in range(n):
# do some computation
bar.update()
stream
(int
): default 2. Takes 1 for stdout, 2 for stderr, or given stream object
In [11]:
n = 150000
bar = pyprind.ProgBar(n, stream=1)
for i in range(n):
# do some computation
bar.update()
In [12]:
bar = pyprind.ProgBar(n, stream=2)
for i in range(n):
# do some computation
bar.update()
In [13]:
import sys
bar = pyprind.ProgBar(n, stream=sys.stdout)
for i in range(n):
# do some computation
bar.update()
The tracking object can be stopped early via the .stop()
method:
In [14]:
n = 150000
bar = pyprind.ProgBar(n)
for i in range(n):
# do some computation
if i == 10000:
bar.stop()
bar.update()
Sometimes it is useful to print out the name of currently processed items, e.g., files are being processed. This can be done by providing a custom string for the optional item_id
parameter of the .update()
method.
In [15]:
import time
items = ['file_%s.csv' %i for i in range(1,21)]
bar = pyprind.ProgBar(len(items))
for i in items:
time.sleep(0.5) # do some computation
bar.update(item_id = i)
In [6]:
import sys
sys.path = ['/Users/sebastian/github/pyprind/'] + sys.path
import pyprind
import time
In [9]:
n = 100
bar = pyprind.ProgBar(n, bar_char='█')
for i in range(n):
time.sleep(0.1) # do some computation
bar.update()
In [ ]: