dka*_*man 4 visual-studio-code vscode-tasks
我有一个静态网站(即只有 html 和客户端 JavaScript),在本地调试时使用 python 提供服务。我有一个 VSCode 任务将正确启动 python,并尝试将该任务设置为preLaunchTaskChrome调试器启动任务。理想的行为是,每当我开始调试serve以下任务时,都会确保站点正在运行。
如果我正确理解后台任务,可以设置beginsPattern和endsPattern来表示状态变化。
我期待当 python 回显时
在 0.0.0.0 端口 8000 ( http://0.0.0.0:8000/ ) 上提供 HTTP 服务...
下面将向启动任务发出信号,表明它已经开始stdout。problemMatcher相反,启动任务会永远等待,直到任务的 shell 命令终止后才会继续。
可以配置任务来实现这种行为吗?
启动配置
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8000",
"webRoot": "${workspaceFolder}/webroot",
"preLaunchTask": "serve"
}
]
}
Run Code Online (Sandbox Code Playgroud)
服务任务
{
"version": "2.0.0",
"tasks": [
{
"label": "serve",
"type": "shell",
"command": "python3 -m http.server",
"windows": {
"command": "py -m http.server"
},
"isBackground": true,
"options": {
"cwd": "${workspaceFolder}/webroot"
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "dedicated"
},
"problemMatcher": {
"owner": "custom",
"pattern":[
{
"regexp": "^([^\\s].*)$",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"activeOnStart": true,
"beginsPattern":"^Serving HTTP (.*)$",
"endsPattern":"^Keyboard interrupt received, exiting(.*)$"
}
}
}
]
}
Run Code Online (Sandbox Code Playgroud)
所以我们也遇到了类似的问题:想要在 Docker 内运行的 Django 应用程序上设置一个调试器。在我的设置中,调试器启动了一个preLaunchTask启动远程解释器调试器的程序,其中包括(例如安装ptvsd.
原始步骤:
preLaunchTask调用脚本(./run-debug.sh )。docker container exec -it my_app python debug.py runserver --noreload --nothreading 0.0.0.0:8000debug.py文件中,有一个打印语句可以知道调试器已启动。显然,这不起作用,VSCode 无法捕获调试器的输出。相反,run-debug.sh我在文件上添加了一条 echo 语句:Starting debugger session:which VSCode catch ^_^。这为我解决了这个问题。
tasks.json,相关问题匹配器:
"problemMatcher": {
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"beginsPattern": "^Starting debugger session:",
"endsPattern": ".",
}
}
Run Code Online (Sandbox Code Playgroud)
run-debug.sh脚本,相关部分:
"problemMatcher": {
"pattern": [
{
"regexp": ".",
"file": 1,
"location": 2,
"message": 3
}
],
"background": {
"beginsPattern": "^Starting debugger session:",
"endsPattern": ".",
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2375 次 |
| 最近记录: |