platformio-vscode-ide
platformio-vscode-ide copied to clipboard
If process unexpectedly quits while debugging, Python will use 100% CPU until force quit
When debugging a program in PlatformIO when using the integrated VSCode debugging experience, I've found that if the process unexpectedly quits (for example because of a seg fault), the underlying Python process gets stuck in a tight loop where it uses 100% CPU and doesn't quit until being force killed. This is not visible in VSCode's Process Explorer view.
This is the command line of the process from ps
:
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python /Users/XXX/.platformio/penv/bin/platformio debug -e native --interface gdb --interpreter=mi2 -q
I originally noticed this when after trying to debug a code issue I found that my laptop fan was going crazy and my laptop battery was draining very quickly.
This is very easy for me to reproduce.
Here's a simple bit of repro code:
int main(int argc, char** argv)
{
char* c;
*c = 'a';
return 0;
}
When I debug into this code, once the process exits due to the seg fault, I can see a Python process using 100% CPU. (It may also be necessary to set a breakpoint before the segfault, but I'm not 100% certain.)
This does not reproduce when using the CLI debugger with pio
, this only reproduces when using the VSCode integrated debugger.
I'm assuming that the gdb shim to VSCode doesn't gracefully handle the process unexpectedly quitting and gets stuck into a bad state when this happens.
This is what my platformio.ini looks like:
[env:native]
platform = native
test_ignore = test_embedded
build_flags = -std=gnu++11
debug_test = test_native
test_build_project_src = true
Environment details
- MacOS 11.6.2
- VSCode: 1.63.2
- PlatformIO extension: 2.4.0
- PlatformIO Core: 5.2.4
Discussion on community forum: https://community.platformio.org/t/debugger-using-huge-amounts-of-cpu-and-battery-until-python-is-force-quit/25512
I wonder if this is at all related to #2683 and the extension using the Xcode version of Python vs the ~/.platformio version.
Note in my repro above its using /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/Resources/Python.app/Contents/MacOS/Python
versus ~/.platformio/python3
.
It wouldn't be the first time Apple's bundled versions of certain tools have different behaviors from mainstream versions.
In haven't had a chance to try to repro this issue on Windows to confirm this hunch, though.
Just a quick update -- I'm seeing this when performing both native debugging on my local machine as well as when doing JTAG debugging against a board. It seems to repro easily by simply stopping a debug session while it's in progress (doesn't repro 100% of the time but enough that I feel it necessary to check running processes every time I stop debugging to kill the runaway Python process if needed). This is making debugging a pretty miserable experience. :(
If there's any more information I can provide that may assist in getting this fixed, please let me know.
Same problem when debugging an esp32 with JTAG. I am using Python 3.10 using PyEnv. Happy to test, if someone has a hint on how to fix this.