-
Notifications
You must be signed in to change notification settings - Fork 127
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
Progress keeps printing after .Stop() #20
Comments
The cause of this issue is that the |
A simple, albeit imperfect workaround is to remove the bars from the progress: progress.Bars = nil it is still not perfect as there will be one more printout when the |
I have the same issue. |
Simplest solution would be to make a copy of the stop chan and use func (p *Progress) Listen() {
p.lw.Out = p.Out
stopChan := p.stopChan
ticker := time.NewTicker(p.RefreshInterval)
for {
select {
case <-stopChan:
ticker.Stop()
return
case <- ticker.C:
p.mtx.RLock()
for _, bar := range p.Bars {
fmt.Fprintln(p.lw, bar.String())
}
p.lw.Flush()
p.mtx.RUnlock()
}
}
} a draft can be found at my branch where I try to fight racing conditions of the Start/Stop for the travis to be happy with my new tests. Even better solution IMHO would be to avoid swapping |
@mgurov, I have tried your fix and here are my findings:
|
@henvic thank you for the feedback. (2. and (3. might be related to #18 - the bar doesn't print out properly. That hints that might fix might need to be extended correspondingly. For example doing that flush on stop. (1. Not clear to me. I guess with the current I won't probably be working very active on a PR before the weekend. Feel free to jump in. |
Regarding 2: with the current master, the behavior is worse (Flushing before stop should fix it). I don't know if I am going to be able to work on a PR, but I'll let you know if I have any news. |
This fixed it for me! Thanks 👍
|
@revett, it should solve for 99.9% of the cases, though you will still find the issue sometimes. |
Simple demonstration:
Expected: bar once printed, as it is stopped after one interval.
Actual: The bar is printed every 10 milliseconds.
The text was updated successfully, but these errors were encountered: