1 Star 0 Fork 0

zhuchance/kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
interrupt_handler.go 808 Bytes
一键复制 编辑 原始数据 按行查看 历史
Jeff Grafton 提交于 2015-04-16 15:47 . Update Gingko to latest HEAD release
package interrupthandler
import (
"os"
"os/signal"
"sync"
"syscall"
)
type InterruptHandler struct {
interruptCount int
lock *sync.Mutex
C chan bool
}
func NewInterruptHandler() *InterruptHandler {
h := &InterruptHandler{
lock: &sync.Mutex{},
C: make(chan bool, 0),
}
go h.handleInterrupt()
SwallowSigQuit()
return h
}
func (h *InterruptHandler) WasInterrupted() bool {
h.lock.Lock()
defer h.lock.Unlock()
return h.interruptCount > 0
}
func (h *InterruptHandler) handleInterrupt() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c
signal.Stop(c)
h.lock.Lock()
h.interruptCount++
if h.interruptCount == 1 {
close(h.C)
} else if h.interruptCount > 5 {
os.Exit(1)
}
h.lock.Unlock()
go h.handleInterrupt()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v0.17.1

搜索帮助

Cb406eda 1850385 E526c682 1850385