@@ -0,0 +1,26 @@
|
||||
package godef
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
"videoweb/pub/common/log"
|
||||
"videoweb/pub/common/tgbot"
|
||||
)
|
||||
|
||||
func Go(f func()) {
|
||||
//atomic.AddInt64(&routineCount, 1)
|
||||
go func() {
|
||||
defer func() {
|
||||
//atomic.AddInt64(&routineCount, -1)
|
||||
if r := recover(); r != nil {
|
||||
buf := make([]byte, 2048)
|
||||
length := runtime.Stack(buf, false)
|
||||
info := string(buf[:length])
|
||||
log.Error("cat a unkown excetion", log.Any("excetion :", info), log.Any("e", r))
|
||||
//发送tg消息
|
||||
msg := "goroutine crash,the stack:\n" + info
|
||||
tgbot.SendToProgram("程序异常", msg)
|
||||
}
|
||||
}()
|
||||
f()
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user