vbauerster / mpb

multi progress bar for Go cli applications
The Unlicense
2.31k stars 123 forks source link

Bar getting stuck if another function writes to stdout #84

Closed JaskaranSM closed 2 years ago

JaskaranSM commented 4 years ago

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.

vbauerster commented 3 years ago

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

Wsyspringsun commented 3 years ago

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

wohenbushuang commented 2 years ago

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.

vbauerster commented 2 years ago

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