vbauerster / mpb

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

Repetition of Incomplete Progress bars #107

Closed sanyamsinghal closed 1 year ago

sanyamsinghal commented 2 years ago

I am using mpb module to display multiple progress bars for some ongoing process. The issue is that progress bar's output is not correct/cleaner. (this issue is important for us since we want to use it in our production code)

The output looks like this:

inventory  completed
country  completed
film  completed
film_actor [---------------------------------------------------------------------------------------------------------------------------------------------------------------------] 0.00%     0s
film_actor  completed
customer  completed
category  completed
film_category  completed
actor  completed
city  completed
rental [-------------------------------------------------------------------------------------------------------------------------------------------------------------------------] 0.00%     0s
payment [=============================================================>----------------------------------------------------------------------------------------------------------] 37.00%    0s
language [-----------------------------------------------------------------------------------------------------------------------------------------------------------------------] 0.00%     0s
payment_p2007_06  completed
payment_p2007_01  completed
payment_p2007_02  completed
rental [========================================================================================================>----------------------------------------------------------------] 62.00%    0s
rental [========================================================================================================>----------------------------------------------------------------] 62.00%    0s
rental  completed
sample [======================================================================================================================================================================>--] 99.00%    0s
sample  completed
temp_testing.sample [=>-------------------------------------------------------------------------------------------------------------------------------------------------------] 1.00%     1m15s
temp_testing.sample  completed
temp_testing.sample2  completed

Here you can see that rental progress bar is displayed/printed twice before competition

rental [========================================================================================================>----------------------------------------------------------------] 62.00%    0s
rental [========================================================================================================>----------------------------------------------------------------] 62.00%    0s
rental  completed

In my usecase, progress bars dynamically gets added the container based on whenever the corresponding thing to track starts.

I believe there might be some issue with the way i am using it in my code. I can share the way i have implemented it, any help would be highly appreciated. cc @vbauerster

sanyamsinghal commented 2 years ago

So in the implementation, first i am creating the progress bar container like this:

progressBarContainer := mpb.New(mpb.PopCompletedMode())

Then i am just calling one goroutine for each progress bar where each progress bar tracks some ongoing work in the main process.

go startPB()

where each call to startPB() function will add a Progress Bar to the container and will increment it till the end. In startPB() function, the way i am creating progress bar is:

bar := importProgressContainer.container.AddBar(total,
        mpb.BarFillerClearOnComplete(),
        mpb.PrependDecorators(
            decor.Name(name),
        ),
        mpb.AppendDecorators(
            decor.OnComplete(
                decor.NewPercentage("%.2f", decor.WCSyncSpaceR), "completed",
            ),
            decor.OnComplete(
                decor.AverageETA(decor.ET_STYLE_GO), "",
            ),
        ),
    )
sanyamsinghal commented 2 years ago

Just to add previous i was creating the container without PopOnComplete() but the issue was when i was having 110 progress bars, then at some point of time for the current Progress Bars whole set of previous progress bars(even though its complete) was repeting and causing the output console to be very much filled by the output.