[英]How can I debug a child_process fork process from visual studio code
Executing child_process.fork
from a vscode debug process fails to run with and returns exit code 12. Running the same test from a terminal session succeeds. 从vscode调试过程执行
child_process.fork
无法运行,并返回退出代码12。从终端会话运行相同的测试成功。
import { expect } from 'chai';
import { fork } from 'child_process';
import path from 'path';
describe('Child Process Fork', () => {
it('Successfully Forks A Simple Process', (done) => {
const child = fork(path.join(__dirname, 'SimplyExit.js'), [], { stdio: 'pipe' });
child.on('exit', (data) => {
expect(data).to.equal(0);
done();
});
});
});
process.exit(0);
Executing child_process.fork
from a parent node process that was started with an inspect-brk
option active will cause this error if you don't manually specify a different inspect-brk
port or remove the option. 如果您没有手动指定其他
inspect-brk
端口或删除该选项,则从以inspect-brk
选项激活的父节点进程执行child_process.fork
将导致此错误。
Here's the line of code in the node.js source that causes this to happen 这是导致这种情况发生的node.js源代码行
Add execArgv: []
to your fork options to prevent the child process from inheriting the inspect-brk
option. 将
execArgv: []
添加到fork选项中,以防止子进程继承inspect-brk
选项。 Here's the full working code. 这是完整的工作代码。
import { expect } from 'chai';
import { fork } from 'child_process';
import path from 'path';
describe('Child Process Fork', () => {
it('Successfully Forks A Simple Process', (done) => {
const child = fork(path.join(__dirname, 'SimplyExit.js'), [], { stdio: 'pipe', execArgv: [] });
child.on('exit', (data) => {
expect(data).to.equal(0);
done();
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.