BLOG

Record, summarize, and improve.

vscode调试模式

Python文件模式

这个是最简单的模式了,只是把当前文件做为入口文件开始调试。只要这个文件能够调用到的其它文件中,你是可以随意打断点,同时查看调用栈及一些全局信息的。

启动它的方式很简单,直接在"Run"这个菜单下选择 “Start Debuging”就可以了,熟悉了还可以直接按“F5”这一个快捷键。

当然了,如果你愿意为此写一个配置文件“launch.json”是最好的,因为这样你能控制更多的信息,也能把它固化下来。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: 当前文件",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }
    ]
}

模块模式

这个模式通常是用来做一些框架开发的基础模式。比如用scrapy,就要这样写一个配置。掌握它,差不多是掌握了大部分你需要的Debug配置了。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: 模块",
            "type": "python",
            "request": "launch",
            "module": "scrapy",
            "cwd": "${workspaceFolder}",
            "args": ["crawl","zhihu"],
        }
    ]
}

远程连接模式

这个也不能说远程吧,就是服务调试模式,通常是用来Attach的。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: 远程连接",
            "type": "python",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ]
        }
    ]
}

使用PID连接模式

这个跟上一个差不多吧,只不过是本机的。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: 使用 PID 连接",
            "type": "python",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

Django模式

这个名字看了就应该很熟嘛,Django相关的配置文件。可以在args里,增加你想要的端口啥的。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "args": [
                "runserver"
            ],
            "django": true
        }
    ]
}

FastAPI模式

这个模式我真没有用过,不太清楚怎么玩。从介绍上看,依然是一个Web框架。难道大Python都用来开发Web了?下次我要介绍一下怎么用Environment,开发人工智能吧。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: FastAPI",
            "type": "python",
            "request": "launch",
            "module": "uvicorn",
            "args": [
                "main:app"
            ],
            "jinja": true
        }
    ]
}

Flask模式

跟Django差不多,有人喜欢它,有人喜欢Django

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "app.py",
                "FLASK_ENV": "development"
            },
            "args": [
                "run",
                "--no-debugger"
            ],
            "jinja": true
        }
    ]
}

Pyramid模式

这也是一个Web开发框架,看来程序员的世界从来不缺乏轮子。但是这个轮子我真的没有学过啊。

{
   "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Pyramid 应用",
            "type": "python",
            "request": "launch",
            "module": "pyramid.scripts.pserve",
            "args": [
                "${workspaceFolder}/development.ini"
            ],
            "pyramid": true,
            "jinja": true
        }
    ]
}