-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bar updates race vs. cancelation #93
Comments
There are 'OnCompete' handlers may be triggered at that point, so despite of completion has happened already, technically bar is still in cancellable state. Sorry for confusing If completion has happened either by naturally reaching total or by manually As for tracking operation timeout case, canceling context will cancel all bars in the container (pool) releasing If your policy is just cancel (abort) particular bar on any unexpected event then you get what you get. |
I have enforced completion check in Abort method: b1d0fee bar := p.AddBar(…)
defer func() {
if !bar.Completed() { // not necessary in next version of course
bar.Abort()
}
} |
Thank you! |
You're welcome! |
(Context: containers/image#1013 and #92 . We might very well be doing something stupid, if so I apologize for wasting your time.)
At a high level, we’d like to differentiate between canceling the “tracked operation” (e.g. a download; we must support such cancelation, e.g. for externally-imposed timeouts) and cancelling the “progress bar machinery” (which we don’t want to do; we’d prefer to terminate it when rendered in a consistent state); and to cancel the tracked operation with minimum hassle.
One way to express this is that terminating
Bar.serve
drops recently-made updates, AFAICS progress is only rendered in intervals, andp.Wait()
does not trigger an immediate re-render.Reproducer: operation that times out does not report full progress.
Output with alternatives 1, 2:
i.e. not updated to the true progress of 1/2. I can’t find a public API to explicitly cause a flush either.
This is admittedly a pretty minor quibble — if the operation has failed, who cares what exactly the progress bars say? — but making this work seems like the same class or problem as making the
SetTotal
+cancel
case work.A variant: calling
bar.Abort()
races against recentbar.SetTotal()
.Motivation: As described above,
p.Wait()
should always be called, but we want to make sure it never hangs. So it would be convenient for EDIT us to usedefer
immediately after creating a progress EDITbarcontainer, or after creating a bar, to ensureBar.serve
is terminated; that can be done using either the context passed tompb.NewWithContext
, which #92 advises against, orbar.Abort()
on each individual progress bar, which documents:Yet
renders
because
Bar.serve
is canceled bybar.Abort
before fully processing the completion.So based on the above, if we wanted to ensure that
p.Wait()
never hangs, it seems that we would have to doThat’s certainly doable, but being able to just pass a cancellable context to
mpb.NewWithContext
and not worry about it would be much nicer.Alternatively, an ability to pass a
context.Context
toProgress.AddBar
could also work well for us — as long as that cancellation only served to terminate thep.Wait()
call, butp.Wait()
still waited for full rendering of the final state.The text was updated successfully, but these errors were encountered: