在我的电子应用程序中,我以可执行文件 (dash.exe) 的形式运行本地服务器实例(一个 Plotly Dash 服务器,它构建在 Python Flask 之上)。每当电子应用程序关闭时,我希望服务器实例也关闭。我曾尝试使用其 PID 终止该进程,但即使我从 kill 命令中返回“true”,该任务仍然继续进行。我曾尝试使用节点包“tree-kill”,但这似乎也没有杀死它。任何帮助将不胜感激。
preload.js
var opt = function(){
const process = execFile(path.join(__dirname, DASH_PATH), function(err, results) {
console.log(err)
console.log(results.toString());
});
ipc.send('processMessage', process.pid);
}
opt();
main.js
var DASH_PID = '';
.
.
.
ipcMain.on('processMessage', (event, args) => {
DASH_PID = args;
})
.
.
.
if(DASH_PID != '') {
let result = process.kill(DASH_PID);
console.log(result) // Prints out true
}