mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 17:59:36 +08:00
feat: catch Interrupt and SIGTERM signals to ensure plugin quitted
This commit is contained in:
15
runner.go
15
runner.go
@@ -9,8 +9,11 @@ import (
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -213,6 +216,18 @@ func initPlugin(path string) (plugin common.Plugin, err error) {
|
||||
go ga.SendEvent(event)
|
||||
}()
|
||||
plugin, err = common.Init(path)
|
||||
|
||||
// catch Interrupt and SIGTERM signals to ensure plugin quitted
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-c
|
||||
if plugin != nil {
|
||||
plugin.Quit()
|
||||
}
|
||||
os.Exit(1)
|
||||
}()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user