程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Debugger never attaches when debugging a local Python 3.11 Azure Function App (Queue Triggered)

发布于2024-12-12 17:46     阅读(502)     评论(0)     点赞(28)     收藏(3)


I have a Python 3.11 Function App that runs locally. I'm developing on Windows 11, and VS Code, fwiw.

I have all of the Azure extensions; I have the Azure Tools extension pack, which includes the Functions extension, installed/enabled. It works great for other types of Function Apps and App Services we use.

func host start starts the application as expected. I am connected to a remote queue storage account -- I can drop messages onto the queue and see it get picked up by my locally-running app.

I'd love to be able to debug and step through the code when it processes a message. However, I have a breakpoint set right where I know code is getting executed, as well as other lines, and I never see them get hit. I know the debugger is not attached, because I don't see the debugger controls

So, I have the following launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Python Functions",
            "type": "debugpy",
            "request": "attach",
            "justMyCode": true,
            "connect": {
                "host": "localhost",
                "port": 7071
            },
            "preLaunchTask": "func: host start",
            "env": {
                "PYDEVD_DISABLE_FILE_VALIDATION": "1"
            }
        }
    ]
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "func",
            "label": "func: host start",
            "command": "host start --port 7071 --enable-debugging",
            "problemMatcher": "$func-python-watch",
            "isBackground": true,
            "dependsOn": "pip install (functions)"
        },
        {
            "label": "pip install (functions)",
            "type": "shell",
            "osx": {
                "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
            },
            "windows": {
                "command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
            },
            "linux": {
                "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
            },
            "problemMatcher": []
        }
    ]
}

My local.settings.json holds nothing exciting:

{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsStorage": "UseDevelopmentStorage=true"
  }
}

Here's a screenshot showing the app is running fine:

screenshot of running app

So what gives? Why, when pushing F5, the Function App spins up fine, but the debugger does not attach?


解决方案


To debug locally and hitting it with a break point, you have to use Start Debugging in Run as below:

enter image description here

Now add a break point and it will hit now, when you click on Start Debugging:

enter image description here

Even when I press F5 it is working with :

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Attach to Python Functions",
            "type": "debugpy",
            "request": "attach",
            "connect": {
                "host": "localhost",
                "port": 9091
            },
            "preLaunchTask": "func: host start"
        }
    ]
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "func",
            "label": "func: host start",
            "command": "host start",
            "problemMatcher": "$func-python-watch",
            "isBackground": true,
            "dependsOn": "pip install (functions)"
        },
        {
            "label": "pip install (functions)",
            "type": "shell",
            "osx": {
                "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
            },
            "windows": {
                "command": "${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
            },
            "linux": {
                "command": "${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt"
            },
            "problemMatcher": []
        }
    ]
}

Try installing the debugpy:

Firstly check if debugpy:

pip show debugpy

enter image description here

If not there install it:

pip install debugpy
pip show debugpy

enter image description here

Upgrade Azure Function Core Tools.

Alternatively, you can also check here:

enter image description here

For further information refer SO-Thread1 and SO-Thread2 and Microsoft-Document.



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:https://www.pythonheidong.com/blog/article/2046610/2f5c1a4ca2e742b01f2c/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

28 0
收藏该文
已收藏

评论内容:(最多支持255个字符)