问题描述
信息
- nodejs 版本:v14.16.0
- 操作系统:Ubuntu 20.04.2 LTS
问题
当 SIGTERM
或 SIGINT
信号发送到进程时,我想关闭 puppeteer 浏览器。
SIGTERM
处理程序按预期工作。
但是 SIGINT
处理程序甚至没有被调用:我尝试使用 ctrl + c
和 kill -s SIGINT <pid>
。
脚本如下:
const puppeteer = require("puppeteer");
async function start() {
const browser = await puppeteer.launch({
args: ["--no-sandBox"],executablePath: "/usr/bin/google-chrome",});
console.log("browser Launched");
browser.on("disconnected",() => console.log("browser disconnected"));
function cleanUp(signal) {
console.log("signal: " + signal);
browser.close();
}
process.on("SIGTERM",cleanUp);
process.on("SIGINT",cleanUp);
}
console.log(process.pid);
start();
我尝试使用这个 python 脚本,SIGINT
处理程序按预期工作。
import signal
import os
import sys
def signal_handler(sig,frame):
print('You pressed Ctrl+C!')
sys.exit(0)
signal.signal(signal.SIGINT,signal_handler)
print('Press Ctrl+C')
print(os.getpid())
signal.pause()
我无法找出问题的根源,将不胜感激。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)