Visual studio code VSCode中后台任务的正确beginsPattern和endsPattern是什么?

Visual studio code VSCode中后台任务的正确beginsPattern和endsPattern是什么?,visual-studio-code,vscode-tasks,Visual Studio Code,Vscode Tasks,我有一个静态网站(即html和客户端JavaScript),在本地调试时使用python提供服务。我有一个可以正确启动python的VSCode任务,我正在尝试将该任务设置为启动任务的preLaunchTask。期望的行为是,每当我开始调试时,下面的service任务都会确保站点得到服务 如果我正确理解后台任务,可以将beginsPattern和endsPattern设置为信号状态更改 我期待着当python响应时 在0.0.0.0端口8000()上提供HTTP服务 到stdout,下面的pro

我有一个静态网站(即html和客户端JavaScript),在本地调试时使用python提供服务。我有一个可以正确启动python的VSCode任务,我正在尝试将该任务设置为启动任务的
preLaunchTask
。期望的行为是,每当我开始调试时,下面的
service
任务都会确保站点得到服务

如果我正确理解后台任务,可以将
beginsPattern
endsPattern
设置为信号状态更改

我期待着当python响应时

在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"
        }
    ]
}
服务任务

{
    "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(.*)$"
                }
            }            
        }
    ]
}

所以我们也遇到了类似的问题:想要在Docker内部运行的Django应用程序上设置一个调试器。在我的设置中,调试器启动了一个
preLaunchTask
,它启动远程解释器调试器,以及其他一些事情(比如安装
ptvsd

原始步骤:

  • preLaunchTask
    调用脚本(
    /run debug.sh
  • 此脚本使用以下命令调用远程调试器:
    docker container exec-it my_app python debug.py runserver--noreload--nothreading 0.0.0.0:8000
  • debug.py
    文件中,有一条print语句,说明调试器已启动
  • 显然,这不起作用,VSCode没有捕获调试器的输出。相反,在
    run debug.sh
    文件中,我添加了一条echo语句:
    启动调试器会话:
    哪个VSCode捕获了^

    tasks.json,相关问题匹配者:

    "problemMatcher": {
                    "pattern": [
                        {
                          "regexp": ".",
                          "file": 1,
                          "location": 2,
                          "message": 3
                        }
                      ],
                      "background": {
                        "beginsPattern": "^Starting debugger session:",
                        "endsPattern": ".",
                    }
                }
    
    运行debug.sh脚本,相关部分:

    #启动远程进程
    echo“正在启动调试器会话:”#VSCode beginsPattern将捕获此消息!
    docker container exec-it my_app python debug.py runserver--noreload--nothreading 0.0.0.0:8000