Start and Stop Python Script from NodeJS?

大城市里の小女人 提交于 2021-02-08 08:01:51

问题


How can I start and stop a python script from a NodeJS server? I have seen the module "python-shell", but it doesn't provide a way to kill the script after running it.


回答1:


Use child_process.

Example from the doc:

const { spawn } = require('child_process');
const child = spawn('python3', ['script.py']);

child.on('close', (code, signal) => {
  console.log(
    `child process terminated due to receipt of signal ${signal}`);
});

// Send SIGTERM to process
child.kill('SIGTERM');


来源:https://stackoverflow.com/questions/45494970/start-and-stop-python-script-from-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!