-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
debugpy: breakpoints not working in core integrations like tuya
#110623
Comments
Hey there @frenck, mind taking a look at this issue as it has been labeled with an integration ( Code owner commandsCode owners of
(message by CodeOwnersMention) debugpy documentation |
Hi, Was looking at this issue for ages in my custom component, not sure if this helps but when I switch to Python 3.11.8 debuggng and breakpoints work fine. On 3.12.x debuging starts but breakpoints are ignored, I could not find out why. Only thing I got was this but pretty sure this is not the issue, can always be wrong.
Not sure if I can offer any other help but happy to do so if I can. |
I can confirm the same problem with 3.12.x. Switching back to Python 3.11.x allows breakpoints to work for both custom integrations as well as core. |
@auphof can you elaborate on how you got this working? Can you do that from the DebugPy integration Service? |
There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. |
I am able to run with debug breakpoints now, slow startup but working. |
I had only partially luck with the configuration above. The internal debugpy module is not catching any breakpoints in my case, even if i could see the debug log messages in the container log. Solution: I did it like this and it worked: Two new files in the same directory of the dockerfile
Build it: docker run or docker-compose up and then Remote Attach with VSCode:
{
// Debug by attaching to remote Home Assistant server using Remote Python Debugger.
// See https://www.home-assistant.io/integrations/debugpy/
"name": "Home Assistant: Attach Remote",
"type": "debugpy",
"request": "attach",
"connect": {
"port": 5678,
"host": "your-ha-instance"
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/usr/src/homeassistant"
}
]
} Everything is catched right from the start. |
On 2024.9: @Devirex's instructions worked for me. It seems like the crux of the issue is that |
Apparently from Python 3.13 you can pass this via an environment flag: https://docs.python.org/3/using/cmdline.html#envvar-PYTHON_FROZEN_MODULES |
Seems that frozen modules has nothing to do with the fix. And actually what fixes debugging is that debugpy module is included earlier than homeassistant module. I was able to debug with this command:
|
The problem
Any breakpoints created in vscode debugger in a component such as
Tuya
don't trigger.For instance I have a breakpoint set at
core/homeassistant/components/tuya/__init__.py
Line 150 in cfd1f78
I have followed instructions from the integration https://www.home-assistant.io/integrations/debugpy. I can remote attach successfully , all the threads are displayed in VSCODE debugger. if i attempt to pause a thread such as the thread Tuya is operating on (Thread ID obtained from Log Record) it does not happen immediately (Possibly async related) but periodically it does pause at some random spot, I can used Debug Console to interrogate the HA objects and step from there, however it never pauses at the intended breakpoint
I note in the Log of the HA container that when i start the DebugPy integration Service it talks about requiring python to be started with
-Xfrozen_modules=off
When I apply that in the service run
python3 -Xfrozen_modules=off -m homeassistant --config /config
then breakpoints function as intendedExpected Outcome
Debug breakpoints in production HA container just work as per integration provided
I realize that might not be achievable so maybe an appropriate Developer Doc is created to support this. see my suggested method below, I am willing to put this as a PR against the develop docs, I am also willing to try other approaches.
A method of Debugging Production HA Containers
To Debug the latest HA Container I built a new container from the following
dockerfile
.This Dockerfile is designed to set up a debugpy tuned containerized environment for debugging Home Assistant, The file outlines several steps to customize the container for fixing the debugpy breakpoints issue performance and potential integration improvements. Here's a breakdown of what each part does:
Base Image: The Dockerfile starts with
FROM homeassistant/home-assistant:latest
, which specifies that the container will be built from the latest version of the Home Assistant Docker image. This image contains all the necessary dependencies to run Home Assistant.Customizing Service Script:
RUN
command replaces the default service script for Home Assistant with a custom one. The script is written to the file/usr/src/homeassistant/rootfs/etc/services.d/home-assistant/run
./etc/services.d/home-assistant/run
. It's written to both places but i think it would work if only written to/etc/services.d/home-assistant/run
. Both scripts:/config
directory, where Home Assistant's configuration files are expected to be found. If this directory does not exist, the script exits with an error.DISABLE_JEMALLOC
environment variable is not set. If it's not set, the script configures the container to usejemalloc
as the memory allocator for Home Assistant, which can offer performance benefits. It does this by setting theLD_PRELOAD
environment variable to preloadlibjemalloc.so.2
and configuringjemalloc
settings viaMALLOC_CONF
.Commented Out Code for Tuya SDK:
manifest.json
file of the Tuya component to require a new version of the SDK.The commented-out sections offer flexibility for developers/testers working with customized but not released 3rd party python modules. Enabling the live testing of changes developed in the Devcontainer approach
Build the modified image on a target platform
Disclosure
Interpretation of the
dockerfile.update
was suggested and edited with aid of ChatGPT4, my human eyes, brain and fingers then modified appropriately 😁What version of Home Assistant Core has the issue?
2024.2.1
What was the last working version of Home Assistant Core?
No response
What type of installation are you running?
Home Assistant Container
Integration causing the issue
seen in TUYA
Link to integration documentation on our website
No response
Diagnostics information
No response
Example YAML snippet
No response
Anything in the logs that might be useful for us?
No response
Additional information
System Information
Home Assistant Community Store
Home Assistant Cloud
Dashboards
Recorder
The text was updated successfully, but these errors were encountered: