signalKit

package
v2.9.114 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ExitSignals 会将程序退出的所有能捕捉的信号
	/*
		参考: go-zero中的"core/proc/signals.go".
	*/
	ExitSignals = []os.Signal{syscall.SIGTERM, syscall.SIGINT}
)

Functions

func MonitorExitSignals added in v2.8.182

func MonitorExitSignals(callbacks ...func(sig os.Signal))

MonitorExitSignals 监听退出信号(拦截关闭信号).

可以参考 go-zero 中的 "core/proc/signals.go".

@param callbacks 可以不传

PS: (1) 无法拦截部分信号(e.g. syscall.SIGSTOP、syscall.SIGKILL); (2) 可以通过 logrus.RegisterExitHandler() 在程序退出前"毁尸灭迹"(在里面你甚至可以 time.Sleep); (3) 此函数对 主动调用os.Exit() 无效; (4) 信号处理函数中不要使用 fmt.Println 等函数,因为它们不是线程安全的,会导致程序崩溃; (5) 虽然可以多次调用本函数,但不推荐这么干,1次就够了.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL