Comments (7)
Note adding wait groups makes no difference.
from mpb.
It just happens that RemoveBar
method never considered "remove after completion done" case, there is nothing to do with thread safety. In fact it is removing the bar from the heap container, but too late in this particular case. It's very tricky to keep track, if initial intention (remove or keep) is unknown. So I would better rename this method to something like RemoveWhile
and better add an option to auto-remove bar after completion. This way, there is no need to call defer p.RemoveBar
.
from mpb.
Is there a way to set the initial intention? ie. remove on completion.
from mpb.
Not yet, but I'm going to add via optional BarOption.
User api would be: p.AddBar(total, mpb.BarRemoveOnComplete())
. As for current p.RemoveBar
, I'm going to rename it to p.Abort
, because imo it would be clear indication what the method does.
from mpb.
I did some refactoring, so following code should work as you wish.
const sleep = 100 * time.Millisecond
func main() {
p := mpb.New()
b1 := p.AddBar(int64(100), mpb.BarRemoveOnComplete(),
mpb.PrependDecorators(decor.StaticName("bar1", 0, 0)))
go func() {
go func() {
time.Sleep(10 * sleep)
b2 := p.AddBar(int64(100), mpb.BarRemoveOnComplete(),
mpb.PrependDecorators(decor.StaticName("bar2", 0, 0)))
for !b2.Completed() {
b2.IncrBy(10) // fastest
time.Sleep(sleep)
}
}()
for !b1.Completed() {
b1.IncrBy(2) // second fastest
time.Sleep(sleep)
}
}()
go func() {
b3 := p.AddBar(int64(100), mpb.BarRemoveOnComplete(),
mpb.PrependDecorators(decor.StaticName("bar3", 0, 0)))
for !b3.Completed() {
b3.IncrBy(1) // slowest
time.Sleep(sleep)
}
}()
p.Wait()
}
from mpb.
Thanks @vbauerster! I'll give this a go next Monday-ish.
from mpb.
Tried it today, seems to be working well! I noticed some slight glitches when firing progressbars that are then quickly removed, but I'll try to come up with a test case for that and report it separately.
from mpb.
Related Issues (20)
- Please make progress.shutdown public HOT 3
- Too many bars = bars repeated? HOT 1
- Display text instead of progress bar HOT 4
- Is there a way to dispose (remove) all the bars after process completed so it doesn't stay in console? HOT 1
- Add support for ReadSeeker for uploads to s3 HOT 5
- Memory leak HOT 5
- Please expose ProxyWriter to public API by analogy with Proxy reader HOT 1
- Panic when calling bar.DecoratorEwmaUpdate inside goroutine HOT 2
- Any option to print logs below progress bar, without progress bar getting duplicated? HOT 3
- if not a TTY, mpb still output control characters HOT 2
- [bytes counter] when use EwmaSpeed ,speed and remain time calculate is wrong? HOT 4
- [QUESTION] Bar doesn't display right info.
- Bug: Bars are not completely removed HOT 3
- Leading white space not removable? HOT 2
- DynTotal with EWMA question HOT 1
- Adding color to one bar on abort adds colors to others in barExtenderRev example HOT 1
- Cannot show up progress bar at Goland terminal console HOT 1
- Ineffective breaks in heap_manager.go HOT 3
- Using Frogbot to scan this repository
- WithWaitGroup hangs on error. Help explain how to use WithWaitGroup. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mpb.