-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't hit debugger breakpoints #198
Comments
That is not something for this repository. |
Pre-ambleOK, fair enough. After many hours of head scratching and searching, I found the issue and figured out a solution. I hope you can figure me posting here because:
ProblemA discussion of the problem can be found here. In short, this has been a known problem with HA's debugpy integration since the change to Python 3.12, which means that frozen modules now need to be explicitly turned off while debugging. Unfortunately, there's no 'easy' way to disable the frozen modules, at least until Python 3.13, which adds an environmental variable. Further running the
SolutionI found the best way to enable debugging was to add a #!/usr/bin/env bash
set -e
cd "$(dirname "$0")/.."
# Create config dir if not present
if [[ ! -d "${PWD}/config" ]]; then
mkdir -p "${PWD}/config"
hass --config "${PWD}/config" --script ensure_config
fi
# Set the path to custom_components
## This let's us have the structure we want <root>/custom_components/area_tree
## while at the same time have Home Assistant configuration inside <root>/config
## without resulting to symlinks.
export PYTHONPATH="${PYTHONPATH}:${PWD}/custom_components"
# Start Home Assistant
#
# See https://github.com/home-assistant/core/issues/110623#issuecomment-2266933072
# Also see https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_FROZEN_MODULES for alternate fix when HA moves to Python 13, using env in launch.json
# Do not set debugpy in configuration.yaml if adding debugpy in command line here...
# To start and wait for remote debugger
python3 -Xfrozen_modules=off -m debugpy --listen localhost:5678 -m homeassistant --config ${PWD}/config For consistency, I renamed {
"version": "2.0.0",
"tasks": [
{
"label": "Run Home Assistant",
"type": "shell",
"command": "scripts/run",
"problemMatcher": []
},
{
"label": "Debug Home Assistant",
"type": "shell",
"command": "scripts/debug",
"isBackground": true,
"problemMatcher": [
{
"owner": "homeassistant",
"pattern": [
{
"regexp": "(.?)",
"file": 1,
"location": 1,
"message": 1
}
],
"background": {
"activeOnStart": true,
"beginsPattern": ".?",
"endsPattern": "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}",
}
}
]
},
{
"label": "Terminate Debug",
"command": "echo ${input:terminate}",
"type": "shell",
"problemMatcher": []
}
],
"inputs": [
{
"id": "terminate",
"type": "command",
"command": "workbench.action.tasks.terminate",
"args": "Debug Home Assistant"
}
]
} Alongside the original The following {
// 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": "Debug Home Assistant",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
],
"preLaunchTask": "Debug Home Assistant",
"postDebugTask": "Terminate Debug",
"justMyCode": false
}
]
} There's no reason for this FutureWhen HA moves to Python 3.13, it may be possible to return to a single script for running/debugging that calls Although a relatively minor set of changes, the time saved for anyone wanting to debug using vscode will be massive. I'd be more than willing to submit a PR if you would be willing to consider it for inclusion? |
Not being able to debug on vs code was the first thing I noticed when I switched Home Assistant development environment. The .vscode folder has the launch.json and extensions.json. |
System Health details
System Information
Home Assistant Cloud
Dashboards
Recorder
Checklist
Describe the issue
Firstly, thank you for this repo which has been a real headstart.
I have managed to get HA running and added the integration. I have also managed to attach the remote debugger in VSCode, however I cannot get it to hit any breakpoints.
Reproduction steps
Reproduction steps
Add the following to HA Config:
Set breakpoint, e.g. on reload.
Start HA using Run Task -
tasks.json
:It will pause, with the following showing in the console
Attach debugger -
launch.json
:On attaching, the console will continue outputting messages, indicating a successful attachment.
Result
Reloading the integration will not hit the breakpoint, nor will any other breakpoints cause the debugger to pause. The debugger will show running threads.
Debug logs
The text was updated successfully, but these errors were encountered: