Comments (8)
func signalHandler() {
// signal handler
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
// do what you want
return
case syscall.SIGHUP:
default:
return
}
}
}
from go-zero.
demo repo: https://github.com/jaronnie/jzero/blob/main/daemon/daemon.go
from go-zero.
Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑🤝🧑👫🧑🏿🤝🧑🏻👩🏾🤝👨🏿👬🏿
But report: https://gityub. Kom/jaron-ie/jzero/bb/main/daemon/daemon. Go
from go-zero.
go-zero already has this logic, but the function 'gracefulStop' did not execute as expected.
core/proc/signals.go
func init() {
go func() {
// https://golang.org/pkg/os/signal/#Notify
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGTERM, syscall.SIGINT)
for {
v := <-signals
switch v {
case syscall.SIGUSR1:
dumpGoroutines(fileCreator{})
case syscall.SIGUSR2:
profiler := StartProfile()
time.AfterFunc(profileDuration, profiler.Stop)
case syscall.SIGTERM:
stopOnSignal()
gracefulStop(signals, syscall.SIGTERM)
case syscall.SIGINT:
stopOnSignal()
gracefulStop(signals, syscall.SIGINT)
default:
logx.Error("Got unregistered signal:", v)
}
}
}()
}
from go-zero.
waitForCalled := proc.AddWrapUpListener(func() {
fmt.Println("wrap up start...")
time.Sleep(5 * time.Second)
fmt.Println("wrap up done")
})
waitForCalled()
from go-zero.
waitForCalled := proc.AddWrapUpListener(func() { fmt.Println("wrap up start...") time.Sleep(5 * time.Second) fmt.Println("wrap up done") }) waitForCalled()
waitForCalled() will block the flow, before server.Start()
from go-zero.
waitForCalled := proc.AddWrapUpListener(func() { fmt.Println("wrap up start...") time.Sleep(5 * time.Second) fmt.Println("wrap up done") }) waitForCalled()waitForCalled() will block the flow, before
server.Start()
Call it after server started.
from go-zero.
server.Start() will block the main thread.
gracefulStop does not wait when i run test()
in a new goroutine.
from go-zero.
Related Issues (20)
- Use gateway server.AddRoute(), The limit(MaxConns) of this route does not take effect HOT 3
- how to exec my own middleware before build-in jwt? HOT 1
- A RPC service generated by multiple proto files? HOT 3
- 'circuit breaker is open','last resolver error: produced zero addresses' HOT 3
- Suggest to add option to disable parameter validation HOT 1
- I've got a problem when I call httpx.Parse() HOT 7
- How to set the part of request params nil ? HOT 1
- Error: sh: goctl-swagger: command not found HOT 1
- How to report trace data to the Monitor of jaeger?
- bug on sql concatenation HOT 2
- Is it possible to support interface in goctl? HOT 1
- Using gateway timeout error, directly go to grpc successfully HOT 2
- Token confusion.
- How does proto define this type? map[string][]int64 HOT 2
- 请问什么时候可以完善go-zero文档,可以参照goframe,文档一定要及时跟随代码迭代进行跟新 HOT 1
- logx support SetFormatter
- Why don't you just use func for logic in existing frameworks? HOT 2
- Why don't you just use func for logic in existing frameworks?
- Why don't you just use func for logic in existing frameworks?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-zero.