I'm working as a programmer for a company that has a complicated setup of repos, so what they've done is set up an EC2 instance with all of the necessary repos and config, and I ssh into it to work on their Python (Flask) backend code. I've been using Jetbrains Gateway as my IDE (it runs an IDE instance on the remote server and then you connect to it with a local client interface, so it looks just like PyCharm but the actual code and IDE features are being executed on the remote server)
I can't figure out how to debug my code. I've used PyCharm's debug feature before but I'm feeling lost in this setup.
I looked at the "Edit Configurations" view and saw that there's a feature called "Python Debug Server", which requires that I specify the IP address of my local machine and a port it is listening on, which the remote EC2 instance will then make a TCP connection to. I don't have a static IP address and I'm not sure that my ISP allows incoming connections like that, so I was looking around online for a service that might help me with that, and saw that ngrok was mentioned in a few places.
I eventually got this working, and thought I'd write up how I did it for anyone else in the future who has this problem:
ngrok tcp --region=us --remote-addr=1.tcp.ngrok.io:12345 12345
Edit Configurations
dialog in Jetbrains Gateway.
pydevd
module into the Python environment you normally use to run the server (whether that's a venv or a base interpreter).
pip install pydevd-pycharm~=241.14494.200
import pydevd_pycharm; pydevd_pycharm.settrace(...)
code somewhere in the app server code where it'll be run (either when you start the app server or when you visit a route you want to debug).sudo systemctl start myappserver
, you may find the values below in a file in your /etc/systemd/system/
directory. So you may want to run something like cat /etc/systemd/system/myappserver.service
.
settrace()
command. Any breakpoints you add to the code should now work (execution should stop at the breakpoint).