-
Notifications
You must be signed in to change notification settings - Fork 107
Debug Python Worker with Azure Functions Host
Hanzhang Zeng edited this page Jan 26, 2021
·
20 revisions
- Clone this repo to your local machine
- Clone the Python Library repo to your local machine
- Clone the Azure Functions Host repo to your local machine
- Make sure your machine has installed Python 3.6/3.7/3.8 and .NETCore SDK 2.2/3.0
- Create a Python 3.6/3.7/3.8 virtual environment .env under azure-functions-python-worker
py -3.8 -m venv .env
- Activate the virtual environment in azure-functions-python-worker/.env
- Run
pip install -e path/to/azure-functions-python-library
to install an editable package of Functions Python library - Run
pip install -e path/to/azure-functions-python-worker
to install an editable package of Functions Python worker - Install the ptvsd library to enable remote debug
pip install ptvsd~=4.3.2
- Run
pip install debugpy
in your virtual envrionment. - In azure-functions-python-worker/python/test/worker.config.json, change defaultExecutablePath to your virtual environment interpreter (e.g. C:/Users/uname/azure-functions-python-worker/.env/Scripts/python.exe).
- In your Azure Functions Host folder, open the WebJobs.Script.sln with Visual Studio.
- Set WebJobs.Script.WebHost as the start up project.
- In WebJobs.Script.WebHost -> Properties -> launchSettings.json, change the environment variables into following
{
"profiles": {
"WebJobs.Script.WebHost": {
"commandName": "Project",
"environmentVariables": {
"languageWorkers:python:workerDirectory": "C:/path/to/your/azure-functions-python-worker/python/test",
"languageWorkers:python:arguments": "-m debugpy --listen 127.0.0.1:9091",
"AzureWebJobsScriptRoot": "C:/path/to/your/functionapp/folder",
"AzureWebJobsStorage": "a storage account connection string",
"AZURE_FUNCTIONS_ENVIRONMENT": "Development"
}
}
}
}
You're now able to debug the function host using your local Python worker
- Use VSCode to open your azure-functions-python-worker
- Add a .vscode folder in the project root
- Add a .vscode/launch.json file with the following content
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach (Remote Debug)",
"type": "python",
"request": "attach",
"port": 9091,
"host": "localhost"
}
]
}
- Add a .vscode/settings.json file with the following content
{
"python.pythonPath": ".env\\Scripts\\python.exe"
}
- Breakpoint
SendWorkerInitRequest
, start WebJobs.Script.WebHost with F5.