Debugging GAE in Python Tools for Visual Studio

UPDATE#2

gcloud preview deprecated

it's back to original method

UPDATE#1

gcloud preview (it's newer and simpler),

replace this:

General->Startup File:

C:\Program Files\Google\Cloud SDK\google-cloud-sdk\lib\googlecloudsdk\gcloud\gcloud.py

Debug->Script Arguments:

preview app run app.yaml --python-startup-script "pydevd_startup.py" --max-module-instances="default:1"

all rest is the same as the original answer below:


ORIGINAL ANSWER:

A.) Create A File to Inject remote debugger

  1. make a new python file "pydevd_startup.py"

  2. insert this:

    import json 
    import sys 
    if ':' not in config.version_id:  
    # The default server version_id does not contain ':'  
        sys.path.append("lib")  
        import ptvsd  #ptvsd.settrace() equivalent  
        ptvsd.enable_attach(secret = 'joshua')  
        ptvsd.wait_for_attach()
    
  3. Save it in your working directory of your app

  4. for more info look at the pytool remote debuging docu I mentioned above

B.) Edit Project Settings in VS 2013

Now open your Project Settings in VS and enter this:

General->Startup File: C:\Cloud SDK\google-cloud-sdk\bin\dev_appserver.py
General->Working Directory: .
Debug->Search Paths: C:\Cloud SDK\google-cloud-sdk\lib
Debug->Script Arguments: --python_startup_script=".\pydevd_startup.py" --automatic_restart=no --max_module_instances="default:1" ".\app.yaml"

You could probably also use . instead of <path-to-your-app> but I wanted to be safe.

C.) Run Debugger

With Ctrl+F5 you run the debugger, without debugging. This sound weird, but we are actually not debugging right now, just running the dev server which than starts our script to inject the debugger code and wait for our remote debugger to connect, which will happen in the next step

D.) Start Remote Debugger

DEBUG->Attach to Process <Ctrl+Alt+P>
Qualifier: tcp://joshua@localhost:5678 <ENTER>

joshua is your secret key. If you want to change it (and you should), you also have to change it in the pydevd_startup.py. See pytool reference for more info.

F.) Be really happy!

You now can remote debug your application locally (erm, weird). To test this you probably should use a breakpoint at the start of your own script.

If you have any question, please ask. In the end it seems really simple, but to get this going was rough. Especially because pytools said, they don't support it...

G.) Start Debugging for real!

Open http://localhost:8080 in a browser (or any other address you configure your app to use). Now it should invoke the breaking point. If you are done and reload the site, it starts all over again. If you really want to end debugging or change some code, you have to restart the server and attach again. Don't forget to close the terminal window with the server open (use <Crtl+C> )


This is a known issue with Google App Engine for Python: currently, debugging does not work on any debugger. See here, here and here.


There's a workaround, but I don't know about getting this working for python tools for vs. In theory it should be possible.

https://groups.google.com/forum/#!topicsearchin/google-appengine/Boa/google-appengine/-m00Qz4Vc7U

You'd probably need this guide to get it working:

https://docs.google.com/document/d/1CCSaRiIWCLgbD3OwmuKsRoHHDfBffbROWyVWWL0ZXN4/edit#heading=h.fj44xnkhr0gr