class VerboseProgressBar(ProgressBar):
def on_iter_begin(self): super().on_iter_begin(); print("on_iter_begin")
def on_interrupt(self): print("on_interrupt")
def on_iter_end(self): print("on_iter_end"); super().on_iter_end()
def on_update(self, val, text): print(f"on_update {val}")
from contextlib import redirect_stdout
import io
tst_pb = VerboseProgressBar(range(6))
s = io.StringIO()
with redirect_stdout(s):
for i in tst_pb: time.sleep(0.1)
assert s.getvalue() == '\n'.join(['on_iter_begin'] + [f'on_update {i}' for i in range(7)] + ['on_iter_end']) + '\n'
tst_pb = VerboseProgressBar(range(6))
s = io.StringIO()
with redirect_stdout(s):
for i in range(7):
tst_pb.update(i)
time.sleep(0.1)
assert s.getvalue() == '\n'.join(['on_iter_begin'] + [f'on_update {i}' for i in range(7)] + ['on_iter_end']) + '\n'
class VerboseMasterBar(MasterBar):
def __init__(self, gen, total=None): super().__init__(gen, VerboseProgressBar, total=total)
def on_iter_begin(self): print("master_on_iter_begin")
def on_interrupt(self): print("master_on_interrupt")
def on_iter_end(self): print("master_on_iter_end")
#def on_update(self, val, text): print(f"master_on_update {val}")
tst_mb = VerboseMasterBar(range(6))
for i in tst_mb: time.sleep(0.1)
tst = NBProgressBar(range(100))
for i in tst: time.sleep(0.05)
tst = NBProgressBar(range(100))
for i in range(50):
time.sleep(0.05)
tst.update(i)
tst.on_interrupt()
mb = NBMasterBar(range(5))
for i in mb:
for j in NBProgressBar(range(10), parent=mb, comment=f'first bar stat'):
time.sleep(0.01)
#mb.child.comment = f'second bar stat'
mb.write(f'Finished loop {i}.')
mb = NBMasterBar(range(5))
mb.update(0)
for i in range(5):
for j in NBProgressBar(range(10), parent=mb):
time.sleep(0.01)
#mb.child.comment = f'second bar stat'
mb.main_bar.comment = f'first bar stat'
mb.write(f'Finished loop {i}.')
mb.update(i+1)
tst = ConsoleProgressBar(range(100))
for i in tst: time.sleep(0.05)
tst = ConsoleProgressBar(range(100))
for i in range(50):
time.sleep(0.05)
tst.update(i)
tst.on_interrupt()
mb = ConsoleMasterBar(range(5))
for i in mb:
for j in ConsoleProgressBar(range(10), parent=mb):
time.sleep(0.01)
#mb.child.comment = f'second bar stat'
mb.main_bar.comment = f'first bar stat'
mb.write(f'Finished loop {i}.')
mb = ConsoleMasterBar(range(5))
mb.update(0)
for i in range(5):
for j in ConsoleProgressBar(range(10), parent=mb):
time.sleep(0.01)
#mb.child.comment = f'second bar stat'
mb.main_bar.comment = f'first bar stat'
mb.write(f'Finished loop {i}.')
mb.update(i+1)
# confirming a kwarg can be passed to ConsoleMasterBar instance
mb.update_graph([[1,2],[3,4]], figsize=(10,5,))
mb.show_imgs(figsize=(10,5,))
from nbdev.export import notebook2script
notebook2script()