📜  停止 python 脚本 nodejs - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:35.012000             🧑  作者: Mango

代码示例1
var python_process;

router.get('/start_python', function(req, res) {
    var PythonShell = require('python-shell');
    var pyshell = new PythonShell('general.py');

    pyshell.end(function (err) {
        if (err) {
            console.log(err);
        }
    });
    python_process = pyshell.childProcess;

    res.send('Started.');
});

// this stops the process
router.get('/stop_python', function(req, res) {
   python_process.kill('SIGINT');
   res.send('Stopped');
});