Debugging service with Pycharm pro
Hi all,
How are you?
I have a Python service that I want to debug by sending a call. Is it possible to debug the Python code invoked by a service call within the application using Pycharm Pro?
The docker container / image is running as expected, in addition as a sanity check, if I call the service from the terminal I get the expected response.
This is a technical question on if and how it's possible to debug the application.
Pycharm version 2023.1
Thanks in advance.
Please sign in to leave a comment.
You can debug the external python process using the python debug server (https://www.jetbrains.com/help/pycharm/remote-debugging-with-product.html#remote-debug-config). Basically, you add a short snippet to your code that instruct the interpreter to connect to PyCharm debugger. If you're running inside Docker, please note that you should expose the port used for the debug server.
Hi Andrey Resler, thank you for your quick response.
So in the case of running inside Docker I should expose the port stated in this line:
in this case 12345 and the IP address is the IP of the server that the App is running on?
And how do I simulate a call to this application?
for example:
curl -H 'Content-Type: application/json' -X POST http://<SERVER IP>:8080/predictions/model -T sample.json | jq .
Just running it from the service terminal and the pycharm will invoke when reaching the breakpoint?
Mista2311 In the settrace() function you need to specify the IP and port of the host where PyCharm is running. Then, when you run this code on the remote host or in the container, it will make a call to PyCharm (which serves as the debug server and listens for connections). You can test that your traffic goes through by using telnet/netcat, or by running a simple python script with pydevd_pycharm.settrace() call.