You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using redirect_stdout=True, attempts to print() after finishing or otherwise write to sys.stdout are lost (not printed to console), unless finish() is called twice. It seems only the second finish call actually restores the old stdout.
Doesn't matter whether using context wrapper or not. If using context wrapper, you must call finish() inside the context to get stdout restored. If not using context wrapper, you must call finish twice.
Following example illustrates. Running this as is, you should see FINISH printed. If you remove that second p.finish() call, you won't see FINISH printed.
Code
importprogressbarimporttimeimportsysm=24514315p=progressbar.ProgressBar(
widgets=[progressbar.Percentage(), progressbar.Bar()],
max_value=m,
redirect_stdout=True,
)
print("START")
forxinrange(0, m, 8192):
time.sleep(0.0001)
p.update(x)
p.finish()
p.finish() # why does it need another finish here?# with progressbar.ProgressBar(# widgets=[progressbar.Percentage(), progressbar.Bar()],# max_value=m,# redirect_stdout=True) as p:# for x in range(0, m, 8192):# time.sleep(0.0001)# p.update(x)## p.finish()print("FINISHED")
Description
When using
redirect_stdout=True, attempts toprint()after finishing or otherwise write to sys.stdout are lost (not printed to console), unlessfinish()is called twice. It seems only the second finish call actually restores the old stdout.Doesn't matter whether using context wrapper or not. If using context wrapper, you must call
finish()inside the context to get stdout restored. If not using context wrapper, you must callfinishtwice.Following example illustrates. Running this as is, you should see FINISH printed. If you remove that second
p.finish()call, you won't see FINISH printed.Code
Versions