Skip to content

Instantly share code, notes, and snippets.

@mau21mau
Created December 28, 2017 16:38
Show Gist options
  • Save mau21mau/5e2366a9a3379d55223b83cae28bcd8e to your computer and use it in GitHub Desktop.
Save mau21mau/5e2366a9a3379d55223b83cae28bcd8e to your computer and use it in GitHub Desktop.
Configure Debug for App Engine python Standard on VSCode

Python Debug for VSCode on Google App Engine

This gist aims to show how to configure debug for VScode and python development on the Google App Engine Standard Environment. This tutorial is based on this article, with some additional information that didn't seem much clear for me.

Step 1: Open the application directory in VSCode.

Step 2: Download the latest version of ptvsd module here. Copy it to your working directory, extract it, than enter the extracted folder (the one that contains setup.py) and copy the ptvsd folder to your root project (where app.yaml resides).

Step 3: Create a tasks.json file with the VSCode command. Press CTRL+SHIFT+B to "Run build task". As no task is configured it will create one from a template which you will have to choose. Once created, place the following content into taksks.json:

Don't forget to change the path to dev_appserver.py

{
    "version": "0.1.0",
    "command": "python",
    "isShellCommand": true,
    "showOutput": "always",
    "args": [
        "<PATH-TO>/dev_appserver.py",
        "--python_startup_script=${workspaceRoot}/pydev_startup.py",
        "--automatic_restart=no",
        "--max_module_instances=default:1",
        "${workspaceRoot}/app.yaml"
    ]
}

Step 3: Create a file named pydev_startup.py with the following contents in the root directory of your application:

import sys
import os
#Assuming that pdvsd is located in the working folder
sys.path.append(os.getcwd())
from .ptvsd import enable_attach
#Fee free to change the secret and port number
enable_attach(secret = 'gae', address = ('0.0.0.0', 3000))
#The debug server has started and you can now use VS Code to attach to the application for debugging
print("Google App Engine has started, ready to attach the debugger")

Step 4: Create a debug configuration with the following entry (in launch.json)

{
    "name": "Google AppEngine Debug Attach",
    "type": "python",
    "request": "attach",
    "host": "localhost",
    "secret": "gae",
    "port": 3000,
    "remoteRoot": "${workspaceRoot}",
    "localRoot": "${workspaceRoot}",
    "preLaunchTask": "python"
}

Step 5: Start the task created earlier using the command CTRL+SHIFT+B (or use Command ‘Run Build Task’ from the Command Palette).

Step 6: This will now open up the Tasks output window and will display information such as the following:

INFO 2016-07-27 05:29:01,672 sdk_update_checker.py:229] Checking for updates to the SDK.

Step 7: Wait until you see the message Google App Engine has started, ready to attach the debugger displaed, as follows:

INFO     2016-07-27 05:29:01,672 sdk_update_checker.py:229] Checking for updates to the SDK.
INFO     2016-07-27 05:29:02,664 api_server.py:205] Starting API server at: http://localhost:52245
INFO     2016-07-27 05:29:02,668 dispatcher.py:197] Starting module "default" running at: http://localhost:8080
INFO     2016-07-27 05:29:02,671 admin_server.py:116] Starting admin server at: http://localhost:8000
Google App Engine has started, ready to attach the debugger

Step 8: Finally, go into the debug configuration and select the Google AppEngine Debug Attach option, and run it.

@golsby
Copy link

golsby commented Dec 8, 2020

Are you able to get this to work with GAE Standard on Python 2.7, using VSCode 1.51.1?

I've followed your instructions (and the original article). I seem to be able to get GAE to get dev_appserver.py to run, but I'm never able to hit breakpoints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment