I have created 2 Python (V2 Programming model) Azure Functions in Vs Code and used a workspace. When I click F5 or start debugging, only the first project session starts debugging, but not the second. When I use func start in terminal for second project, it starts the project but I need to debug rather than just run. Following are my configuration files -
Launch.json
{
"configurations": [
{
"name": "Attach to Preferences",
"type": "python",
"request": "attach",
"port": 9091,
"preLaunchTask": "func: host start",
"project": "${workspaceFolder}/API.Preferences"
},
{
"name": "Attach to Charts",
"type": "python",
"request": "attach",
"port": 7071,
"preLaunchTask": "func: host start",
"project": "${workspaceFolder}/API.Charts"
}
]
}
Settings.json
{
"azureFunctions.deploySubpath": ".",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.pythonVenv": ".venv",
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.projectLanguageModel": 2,
"azureFunctions.projectSubpath": "API.Charts"
}
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)",
"options": {
"cwd": "${workspaceFolder}/API.Preferences"
}
},
{
"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": [],
"options": {
"cwd": "${workspaceFolder}/API.Preferences"
}
}
]
}
code.workspace.json file
{
"folders": [
{
"path": ".."
},
{
"path": "../API.Preferences"
},
{
"path": "../API.Charts"
}
],
"settings": {
"debug.internalConsoleOptions": "neverOpen"
},
"launch": {
"configurations": [],
"compounds": [
{
"name": "Attach to both apps",
"configurations": [
"Attach to Preferences",
"Attach to Charts"
]
}
]
}
}
Any help would be greatly appreciated
Refer my SO answer here
Thus instead of creating separate folders for each Function Trigger, You need to add both the triggers in the same
function_app.pyfile for it to debug together. As, You have created Function project separately in another folder, you need to manually visit the specific Function Project folder root and run func host start to run and debug the individual Function. If you want to keep the Function triggers in separate file you can create blueprint implementation by referring my SO answer here, Where I have referenced 2 of my SO threads for the blueprint and multiple folder implementation.function_app.py:-I have created
Http_triggerthen addedTimer_triggerin the same file, You can also create separate blueprint file for the same:-Output:-
I clicked
fn + F5 buttonorF5and both the Functions got executed together:-