发布于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:
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:
Now add a break point and it will hit now, when you click on Start Debugging:
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
If not there install it:
pip install debugpy
pip show debugpy
Upgrade Azure Function Core Tools.
Alternatively, you can also check here:
For further information refer SO-Thread1 and SO-Thread2 and Microsoft-Document.
作者:黑洞官方问答小能手
链接:https://www.pythonheidong.com/blog/article/2046610/2f5c1a4ca2e742b01f2c/
来源:python黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 python黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-1
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!