PyCharm remote debugging question

  • I have a django project that runs fine (both locally and on a remote server).
  • I start pycharm locally using a "remote debugging" profile and it looks fine.
    • I see "Starting debug server at port 4000"...... "Waiting for connection"
  • On the remote server, I put the appropriate call to pycharm-debug.egg in __init__.py (but I've put it other places in the code, too). More detail included below.
  • I start the remote server and on the local pycharm IDE/debugger I see:
    • "Connected to pydev debugger (build 133.1347)"
  • After this, things just sit there... I don't get any feedback on where execution is and no ability in the pycharm IDE to "start/continue/run" anything.
  • On the remote server if I <ctrl-c> it, I see:
    •    File "/<path here>/pycharm-debug.egg/pydevd.py", line 1256, in settrace
    •    File "/<path here>/pycharm-debug.egg/pydevd.py", line 1305, in _locked_settrace

My guess is that everything is connected properly but I am not seeing a way to start everything running. I have "suspend=False" so I would have expected it to start (more details below). When I try to bring up a page against the remote server, I get "not connected" so the web server is obviously not running yet. Without remote debugging, this works fine.

What am I doing wrong? :)   Thanks!

Details:

  • Remote server that is running the code/process I want to debug:
    • In main __init__.py I have :
      • import os
      • import sys
      • BASE_DIR = os.path.dirname(os.path.dirname(__file__))
      • sys.path.append(BASE_DIR + '/pycharm-debug.egg')
      • import pydevd
      • pydevd.settrace('<my local machine's public ip addr>', port=4000, suspend=False)

  • Local pycharm IDE shows this:
    • Starting debug server at port 4000
    • Use the following code to connect to the debugger:
    • import pydevd
    • pydevd.settrace('localhost', port=4000, suspend=False)  (tried with <public ip addr> for this, too.
    • Waiting for connection...
    • —- and then, after I start the remote server process: —-
    • Connected to pydev debugger (build 133.1347)

Other notes:
  • I've tried this both using virtualenv and not on the remote server.
  • I'm running the local pycharm IDE behind a normal Comcast cable modem router with port-forwarding for port 4000 turned on (and tested this with a node server attaching to port 4000 and worked fine when I did a wget against it from my remote server).

I'm at a loss as to how to "bump" anything to get things running and let me start debugging.

Thanks for trying to help.
7 comments
I am having similar issues. Does anyone one know how to solve this?
0
I did get remote debugging going but not via this method. Instead, I went to "PyCharm/Preferences/Project Interpreter". You'll see an option to choose which python interpreter at the top of the dialog. Next to that is a gear icon. If you click on the gear icon, you'll see an option to "add remote" ... you give it ssh credentials (or path to ssh keys) and the path to where your python interpreter is installed on the remote server (i.e., "/usr/local/bin/python"). In addition, the "pycharm helpers path" for me was ("/home/<username>/.pycharm_helpers" - I can't remember if this was created automatically or not). Once you have that set up, then you go to "Run / Edit Configurations..." and add a "Django Server" (plus sign at top left of dialog). Choose your new remote python interpreter as the interpreter to use (it should show up in a drop-down list of choices). In the "env vars" section I needed to specify my main app settings file (i.e., "DJANGO_SETTINGS_MODULE = <app>/settings.py"). For my purposes I also needed to set "HTTPS=1". Set the working directory to wherever your django project is on the remote server (i.e., "/home/<username>/<xyz>/<appdir>"). Set the path mappings from your local dir to the remote dir (i.e., "/Users/JohnQ/<xyz>/<appdir>=/home/<username>/<xyz>/<appdir>"). Because I needed other 3rd party servers (like FB, etc.) to be able to hit this server using HTTPS, I used "stunnel" on my remote server – it was pretty easy to set up).

In addition to this, a handy thing to do is set up deployment configuration as well so that you can just right-click to upload newer versions of your file (under "Tools / Deployment / Configurations..."). Create a new one and under connection just use ssh creds or path to your keys. In the mappings tab, the paths are the same as what you did for the path mappings for the remote server setup. "Web path on server" was just "/" for me. After you create it, you should just be able to right-click on any file/dir and choose "Upload to...". Note that for an initial upload I just scp'd a tar.gz up to my server to save time and I only upload via the deployment configuration for the changes I do during debugging.

Good luck!
0
I tried to follow your debug configurations. I get the debug server running when I click the debug toolbar button in PyCharm. But for some reason my breakpoints are not getting activated/hit.
0
breakpoints are not getting activated/hit.


Only thing I can think of is that it's not actually running the remote interpreter. You have the option to choose which django server is being debugged when you click the debug toolbar button (there should be a dropdown). Make sure you've chosen the django server that you've configured to use the remote python interpreter. Also double check to make sure that python interpreter chosen for the django server config you're debugging is, in fact, the remote python interpreter. There should be options along the way to "test connection". Your console/debug output when you starting debugging should look something like this:  "ssh://<your username>@<your server>:22/usr/local/bin/python -u /home/<your username>/.pycharm_helpers/pydev/pydevd.py –multiproc –client '0.0.0.0' –port 57402 –file /home/<your username>/<path to project on your server>/manage.py runserver <your domain>:8000"

also... are you able to upload files using the deployment config? That would also indicate whether the client is actually able to login to the server correctly, etc.
0
Thanks for your help.

Yes, I am able to upload files to remote server (docker container): Here is the console output when I start debug in pyCharm:


ssh://docker@localhost:1338/usr/bin/python -u /home/docker/.pycharm_helpers/pydev/pydevd.py –multiproc –client '0.0.0.0' –port 46941 –file /home/docker/hydroshare/manage.py runserver 0.0.0.0:8001
Connected to pydev debugger (build 135.1057)
pydev debugger: process 234 is connecting

/usr/local/lib/python2.7/dist-packages/mezzanine/utils/conf.py:59: UserWarning: TIME_ZONE setting is not set, using closest match: None
  warn("TIME_ZONE setting is not set, using closest match: %s" % tz)
/home/docker/hydroshare/hs_core/models.py:25: DeprecationWarning: django.utils.simplejson is deprecated; use json instead.
  from django.utils import simplejson as json

pydev debugger: process 249 is connecting

/usr/local/lib/python2.7/dist-packages/mezzanine/utils/conf.py:59: UserWarning: TIME_ZONE setting is not set, using closest match: None
  warn("TIME_ZONE setting is not set, using closest match: %s" % tz)
/home/docker/hydroshare/hs_core/models.py:25: DeprecationWarning: django.utils.simplejson is deprecated; use json instead.
  from django.utils import simplejson as json

Validating models...

0 errors found
September 22, 2014 - 04:30:04
Django version 1.6.1, using settings 'hydroshare.settings'
Starting development server at http://0.0.0.0:8001/
Quit the server with CONTROL-C.
0
The thing that stands out for me is "localhost" ...  if you're debugging on localhost, you don't need the remote debugging stuff and it's probably interfering. For me, the server that everything is running on is a Rackspace linux server (i.e., xyz.net:22) ... and I'm running PyCharm locally on my mac and it's ssh'ing into that server. So if you're running things all locally then you can set things up without remote debugging (for that JetBrains documentation is the best source).
0
I have named my sftp host (docker container)that is running my django web app as 'localhost'. I am running an ubuntu vm and PyCharm is installed there. Within the VM I am then running a docker container that runs the django application. That's why I think need remote debugging.

Thanks.
0

Please sign in to leave a comment.