fix: reuse plugin instance if it already initialized

This commit is contained in:
xucong053
2022-07-05 20:15:42 +08:00
parent 481b19c3e6
commit d9829277de

View File

@@ -27,6 +27,8 @@ const (
const projectInfoFile = "proj.json" // used for ensuring root project
var pluginMap = map[string]funplugin.IPlugin{} // used for reusing plugin instance
func initPlugin(path, venv string, logOn bool) (plugin funplugin.IPlugin, err error) {
// plugin file not found
if path == "" {
@@ -37,6 +39,11 @@ func initPlugin(path, venv string, logOn bool) (plugin funplugin.IPlugin, err er
return nil, nil
}
// reuse plugin instance if it already initialized
if p, ok := pluginMap[pluginPath]; ok {
return p, nil
}
pluginOptions := []funplugin.Option{funplugin.WithLogOn(logOn)}
if strings.HasSuffix(pluginPath, ".py") {
@@ -69,6 +76,9 @@ func initPlugin(path, venv string, logOn bool) (plugin funplugin.IPlugin, err er
return
}
// add plugin instance to plugin map
pluginMap[pluginPath] = plugin
// catch Interrupt and SIGTERM signals to ensure plugin quitted
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)