visual studio – Unable to attach and debug a Python script launched by ROS2

I have Visual Studio 2022 Professional with Python module installed.

If I start a Python script from a console, then open Visual Studio, attach the python.exe process, open the Python file, set a breakpoint, I see the breakpoint correctly setup, it gets reached, execution is stopped and then I can debug the script step by step.

Now, I’m using ROS2 humble. I run ros2 run demo_nodes_py talker, this ends up starting a Python interpreter running <ros folder>\Lib\site-packages\demo_nodes_py\topics\talker.py.

But then, when if attach this Python process in Visual Studio and open the talker.py file, I set a breakpoint, but it remains unresolved by Visual Studio (empty red circle) and execution never gets interrupted.

I added in the script a print of the process ID (os.getpid()) and the file path ((str(Path( __file__ ).absolute())), so I’m sure I attached the good process and opened the good file.

Is there anything in the environment that could make Visual Studio unable to resolve breakpoint and let me debug my app?

Read more here: Source link