这是indexloc提供的服务,不要输入任何密码
Skip to content

Start and Stop twice make program panic #40

@jtbonhomme

Description

@jtbonhomme

Hello,
I may be missing a point, but it seems that starting and stoping a uiprogress twice make the program panic.

Please find bellow a short test program:

package main

import (
    "fmt"
    "time"

    "github.com/gosuri/uiprogress"
)

func createbar() {
    uiprogress.Start()
    defer uiprogress.Stop()
    // create a new bar and prepend the task progress to the bar
    count := 100
    bar := uiprogress.AddBar(count).AppendCompleted().PrependElapsed()
    bar.PrependFunc(func(b *uiprogress.Bar) string {
        return fmt.Sprintf("Task (%d/%d)", b.Current(), count)
    })

    for i := 0; i < count; i++ {
            bar.Incr()
            time.Sleep(time.Millisecond * time.Duration(50))
    }
    time.Sleep(time.Millisecond * time.Duration(500))
}

func main() {
  createbar()
  createbar()
}

The console:

$ go run main.go
Task (100/100)    5s [====================================================================] 100%
Task (1/100)    0s [--------------------------------------------------------------------]   1%
panic: close of closed channel

goroutine 20 [running]:
github.com/gosuri/uiprogress.(*Progress).Listen(0xc00007a1e0)
	/Users/jtbonhomme/Developments/golang/src/github.com/gosuri/uiprogress/progress.go:117 +0x12f
created by github.com/gosuri/uiprogress.(*Progress).Start
	/Users/jtbonhomme/Developments/golang/src/github.com/gosuri/uiprogress/progress.go:134 +0x3f
exit status 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions