Search code examples
pythonvisual-studioazurekubernetescontainers

Azure dev spaces to debug python code running in kubernetes pod


How to debug the code written in python in container using azure dev spaces for kubernetes ?


Solution

  • Debugging should be similar just like we have it in Dot net core. In dot net , we used to debug something like this

    Setting and using breakpoints for debugging

    If Visual Studio 2017 is still connected to your dev space, click the stop button. Open Controllers/HomeController.cs and click somewhere on line 20 to put your cursor there. To set a breakpoint hit F9 or click Debug then Toggle Breakpoint. To start your service in debugging mode in your dev space, hit F5 or click Debug then Start Debugging.

    Open your service in a browser and notice no message is displayed. Return to Visual Studio 2017 and observe line 20 is highlighted. The breakpoint you set has paused the service at line 20. To resume the service, hit F5 or click Debug then Continue. Return to your browser and notice the message is now displayed.

    While running your service in Kubernetes with a debugger attached, you have full access to debug information such as the call stack, local variables, and exception information.

    Remove the breakpoint by putting your cursor on line 20 in Controllers/HomeController.cs and hitting F9.

    Try something like this and see if it works.

    Here is an article which explains debugging python code in visual studio 2017

    https://learn.microsoft.com/en-us/visualstudio/python/tutorial-working-with-python-in-visual-studio-step-04-debugging?view=vs-2017