mpb icon indicating copy to clipboard operation
mpb copied to clipboard

Bar getting stuck if another function writes to stdout

Open JaskaranSM opened this issue 4 years ago • 3 comments

Hi, The Library works really nice. but there is just one problem i m having, i m using the library for concurrent progress bars with dynamic addition of bars in Progress pool, if some function call writes to stdout, then the bar that pool was showing gets stuck. however the pool does preserve the bar at the last line of stdout. its just, it is expected to remove that old stuck bar from stdout also. when it moves to the last line. i can share the code if you need for debugging. thanks.

JaskaranSM avatar Oct 21 '20 12:10 JaskaranSM

It's known limitation. PB is written to stdout by default. Its output may be corrupted if another party writes to stdout while PB is rendering. There is some api which allows to circumvent this at some extent: BarExtender BarFillerMiddleware

vbauerster avatar Nov 04 '20 08:11 vbauerster

请问这个问题是如何解决的? Same problem, how to resolve it?

Wsyspringsun avatar Oct 09 '21 03:10 Wsyspringsun

similar problem, and i think BarExtender and BarFillerMiddleware solution is too complicated. sometimes i just want to print some warnings or logs that don't need to be refreshed anymore, and then mpb can move down.

now we have

Task: 6769 / 7200 [======================================================================================================================================================>----------]  94 %  717.3 it/s 0s 10s 
[WARN] xxxxxxx
Task: 7200 / 7200   100 %  655.3 it/s done in 10s

but i expect

[WARN] xxxxxxx
Task: 6769 / 7200 [======================================================================================================================================================>----------]  94 %  717.3 it/s 0s 10s 

and then

[WARN] xxxxxxx
Task: 7200 / 7200   100 %  655.3 it/s done in 10s

maybe it's better to provide an io pipe for developers, then mpb will dump the pipe into stdout before bar rendering in each refresh cycles.

wohenbushuang avatar Nov 30 '21 07:11 wohenbushuang

Implemented in v8. https://pkg.go.dev/github.com/vbauerster/mpb/v8#Progress.Write https://github.com/vbauerster/mpb/blob/master/_examples/progressAsWriter/main.go

vbauerster avatar Sep 04 '22 14:09 vbauerster