我对Visual代码和集群有一些问题。
编辑
如果我点击了Ctrl + F5,它的工作正常,它所做的不仅仅是F5,是否需要始终使用Ctrl启动命令?
-
当开始使用VS代码启动命令(F5)时,工作人员似乎从不启动。我是否需要对..vscode/unch.json文件进行一些更改,以使集群正常工作。
实际代码是从Node.js 6 api cluster复制的。
npm测试 Windows命令提示符显示如下:
Master started
Listening port 80
Listening port 80
Listening port 80
Listening port 80与代码(F5)调试控制台显示如下:
node --debug-brk=7601 --nolazy index.js
Debugger listening on port 7601
Master started
Debugger listening on port 7602
Debugger listening on port 7603
Debugger listening on port 7604
Debugger listening on port 7605与代码launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/index.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
..........index.js
const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
console.log('Master started')
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
cluster.on('exit', (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {
// Workers can share any TCP connection
// In this case it is an HTTP server
http.createServer((req, res) => {
res.writeHead(200);
res.end('hello world\n');
}).listen(80);
console.log('Listening port 80')
}发布于 2016-10-12 11:33:30
我也有过同样的问题。weinand在https://github.com/Microsoft/vscode/issues/3201中描述的第二个解决方案为我工作:
从终端启动节点并使用VS代码调试器附加到该节点。 在终端中运行:节点-调试app.js 然后选择默认的“附加”启动配置并附加到它。 如果您实际上希望调试任何工作人员,而不仅仅是启动的第一个进程,那么解决方法是首选的方法。
发布于 2016-05-06 16:16:30
在带有集群的Visual代码中,我也遇到了同样的问题。
我发现有一些肮脏的方法让它起作用。
Mac:
/Applications/Visual Code.app/Contents/Resources/app/extensions/node-debug/out/node/nodeDebug.js
窗口:
C:\程序文件(x86)\Microsoft对Code\resources\app\extensions\node-debug\out\node\nodeDebug.js
改变这个
if (!this._noDebug) {
launchArgs.push("--debug-brk=" + port);
}至
if (!this._noDebug) {
launchArgs.push("--debug=" + port);
}我知道这不是最好的解决办法,但到目前为止,它对我是有效的。
https://stackoverflow.com/questions/37012179
复制相似问题