Skip to content
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

Duration becomes 0 after calling finish() #557

Open
suomela opened this issue Jul 2, 2023 · 5 comments
Open

Duration becomes 0 after calling finish() #557

suomela opened this issue Jul 2, 2023 · 5 comments

Comments

@suomela
Copy link

suomela commented Jul 2, 2023

If I have got a ProgressBar with ProgressStyle that uses a template like "… {elapsed}/{duration} …". As usual, I repeatedly call .inc(…) and finally .finish(). However, I am typically getting this kind of printout:

  • 0s/4s
  • 1s/4s
  • 2s/4s
  • 3s/4s
  • 4s/4s
  • 4s/0s

That is, the estimated total duration makes plenty of sense, except that after calling finish it drops to 0. I would expect that duration would reflect the real final duration when the progress bar is finished.

I guess the problem is around lines 292–297 of src/state.rs:

pub fn duration(&self) -> Duration {
    if self.len.is_none() || self.is_finished() {
        return Duration::new(0, 0);
    }
    self.started.elapsed() + self.eta()
}

It seems to be explicitly returning 0 when is_finished(). Is this intentional?

@djc
Copy link
Member

djc commented Jul 3, 2023

"Intentional" is a big word. 😄 I suppose we don't ever store the time when we finished, so we don't really have any better value we can show here. I suppose we could add an Instant to the Done variants of Status?

suomela added a commit to suomela/indicatif that referenced this issue Jul 3, 2023
@suomela
Copy link
Author

suomela commented Jul 3, 2023

@djc To me it seems that elapsed works well both before and after finish, and eta is explicitly set to 0 after finish, so if we just removed the part || self.is_finished() in line 293 and let it fall back to elapsed + eta, shouldn't it behave better?

I tried it out here and it seems to work: https://github.com/suomela/indicatif — there's examples/elapsed-duration.rs for playing with this, and a one-line fix attempt in this commit.

@djc
Copy link
Member

djc commented Aug 1, 2023

It might work well immediately after finish, but if a redraw happens sometime after finishing, then elapsed will continue to move forward, which I don't think makes sense.

@suomela
Copy link
Author

suomela commented Aug 2, 2023

I see, I think {elapsed} then has the same issue with redraws?

@djc
Copy link
Member

djc commented Aug 2, 2023

I was talking about elapsed. I haven't actually tried but based on the code I think that would be the effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants