Commit d02efaca authored by liuxiaomin's avatar liuxiaomin

optimization:enhance robustness

parent 3cf58709
...@@ -21,8 +21,11 @@ import ( ...@@ -21,8 +21,11 @@ import (
"fmt" "fmt"
"log" "log"
"math/rand" "math/rand"
"os"
"runtime/debug"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time"
) )
import ( import (
...@@ -171,7 +174,15 @@ func (p *TaskPool) run(id int, q chan task) error { ...@@ -171,7 +174,15 @@ func (p *TaskPool) run(id int, q chan task) error {
case t, ok = <-q: case t, ok = <-q:
if ok { if ok {
t() func() {
defer func() {
if r := recover(); r != nil {
fmt.Fprintf(os.Stderr, "%s goroutine panic: %v\n%s\n",
time.Now(), r, string(debug.Stack()))
}
}()
t()
}()
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment