我试图启动多个程序,这些程序需要在VS Code中的调试器中相互通信,并使用启动每个可执行文件的化合物创建了一个launch.json。程序同时启动,并且所有程序都尝试同时连接到主机。在VS Code中是否有任何方法可以在每个可执行文件的启动之间明确设置某种时间延迟,比如250ms左右?
{
"version": "0.2.0",
"configurations": [
{
"name": "Host",
"type": "cppdbg",
"request": "launch",
"program": "/home/user/build/bin/host",
"args": [],
"stopAtEntry": false,
"cwd": "/home/user/build/bin",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
},
{
"name": "Node A",
"type": "cppdbg",
"request": "launch",
"program": "/home/user/build/bin/Node_A",
"args": ["ArgA","ArgB","ArgC"],
"stopAtEntry": false,
"cwd": "/home/user/build/bin",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
},
{
"name": "Node B",
"type": "cppdbg",
"request": "launch",
"program": "/home/user/build/bin/Node_B",
"args": ["ArgA","ArgB","ArgC"],
"stopAtEntry": false,
"cwd": "/home/user/build/bin",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
}
],
"compounds": [
{
"name": "System",
"configurations": ["Host","Node A","Node B"]
}
]
}
答案 0 :(得分:0)
是的,您可以添加一个预启动任务,该任务将休眠x秒。
因此,假设您在Node.js上有一个客户端和服务器,并且服务器数据库连接的加载时间更长,这会导致客户端出现问题。
在Mac OS X上像这样在vscode上延迟客户端调试器就可以了
首先在与名为tasks.json的launch.json文件相同的文件夹中创建一个任务,该文件将在启动客户端之前构建一个shell命令。
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Sleepdelay",
"type": "shell",
"command": "sleep 6",
"windows": {
"command": "ping 127.0.0.1 -n 6 > nul"
},
"group": "none",
"presentation": {
"reveal": "silent",
"panel": "new"
}
}
]
}
现在将以下预任务添加到launch.json文件中以调用任务
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Client",
"url": "http://localhost:9090",
"webRoot": "${workspaceFolder}/client/src",
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*"
},
"preLaunchTask": "Sleepdelay"
//"runtimeExecutable": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
},
{
"type": "node",
"request": "launch",
"name": "Server",
"program": "${workspaceFolder}/server/server.js",
"envFile": "${workspaceFolder}/server/.env",
"cwd": "${workspaceFolder}/server/"
}
],
"compounds": [
{
"name": "Server/Client",
"configurations": ["Server", "Client"]
}
]
sleep命令仅适用于MAC OS X。
对于Windows,只需使用此hack即可。
ping 127.0.0.1 -n 6> nul
现在,您有一种简单的方法可以延迟客户端在服务器之前启动。