Independent game developers - making Avoyd

Python Google App Engine debugging with PyTools

Juliette Foucaut - 14 Aug 2014 - edited 31 Dec 2014


[Update 12 Aug 2015 - The methods described below do not work in Visual Studio 2015 PTVS with GAE 1.9.17 or above. We haven't found a new workaround. We've switched to using the free PyCharm CE which works great. See our tutorial to configure it.]

For python code destined to run on Google App Engine, we needed an IDE with comprehensive local debugging abilities, i.e. breakpoints, step-by-step execution and variables watch. PyCharm Professional Edition does all this [Edit 31 Dec 2014: for PyCharm Community Edition GAE configuration, see our tutorial], but we chose instead to use a free solution from Microsoft called Python Tools for Visual Studio (a.k.a. PTVS or PyTools). [Edit 28 Nov 2014: now Microsoft Visual Studio Community]

Sadly, due to a bug, breakpoints don't get hit when debugging dev_appserver.py. After lots of searching and trial and error, we found out that an acceptable workaround is to configure Visual Studio as follows:

  • use the deprecated version of GAE's dev_appserver.py: old_dev_appserver.py
  • ignore the unhandled ZipImportError
  • bypass the GAE Launcher.

Once setup, using it is no different from normal debugging. The downside is that some newer GAE functionality won't work.

As a side note, if you need to use dev_appserver.py to get the latest functionality, follow the instructions on Joe's Dev Notepad's blog. The unfortunate downside of that method is you have to repeat the Attach to Process operation every time you debug (if you know how to avoid it drop us a word). It's also relatively slow to start but you can speed it up if you only include the last 3 lines of code in "pydevd_startup.py":

import ptvsd  #ptvsd.settrace() equivalent
ptvsd.enable_attach(secret = 'joshua')
ptvsd.wait_for_attach()

Now let's go back to our workaround.

Note: we're running Microsoft Python Tools for Visual Studio version 2.0.11016.00 and Python 2.7 with Google App Engine SDK 1.9.9 on Windows 8.0. [Edit 28 Nov 2014: both workarounds still work with Microsoft Visual Studio Community 2013 Version 12.0.31101.00 Update 4 with GAE 1.9.13]

Visual Studio configuration

Set Project properties

  1. In VS, open the project containing your Python code

  2. Select menu Project > Properties >

    • Select the General tab

      • set Startup file to: <path to old_dev_appserver.py>
        Example: "C:\Program Files (x86)\Google\google_appengine\old_dev_appserver.py"

      • set Working Directory to: ..

    • Python Tools for Visual Studio's Project Properties General settings - workaround for bug causing python Google App Engine debugging to miss breakpoints: use old_dev_appserver.py instead of dev_appserver.py

    • Select the Debug tab

      • Set Launch Mode to: Standard Python Launcher

      • Set Script Arguments to: --port <unused port number> <project path>
        Example: "--port 8800 C:\Projects\Prototype1"

    • Python Tools for Visual Studio's Project Properties Debug settings - workaround for bug causing python Google App Engine debugging to miss breakpoints

  3. Save the project.

Set debug exception

  1. In VS, select menu Debug > Exceptions...

  2. Select Add…

    1. Set Type to: Python Exceptions

    2. Set Name to: google.appengine.dist.py_zipimport.ZipImportError

    3. Press OK

  3. Python Tools for Visual Studio's - adding python debug exception google.appengine.dist.py_zipimport.ZipImportError

  4. In the exceptions list, expand Python Exceptions. Locate the item google.appengine.dist.py_zipimport.ZipImportError and uncheck the User-unhandled checkbox

  5. Python Tools for Visual Studio's - uncheck User-unhandled setting for python debug exception google.appengine.dist.py_zipimport.ZipImportError

  6. Press OK.

Debugging

  1. in Visual Studio, set breakpoint(s) in your python code and press Start. DO NOT use the Google App Engine launcher.

    A python.exe command window opens with a warning regarding the use of a deprecated version of dev_appserver.py, the port the app is running on, and how to open the admin console.

    In our example we've configured port 8800 in the project's debug properties. As a result, the web application runs at http://localhost:8800 and the admin console is available at http://localhost:8800/_ah/admin.

  2. Open a browser and navigate to http://localhost:<debug port number>. When breakpoints are hit, focus returns to the IDE.

[Edit 28 Nov 2014: added the advanced workaround using the current dev_appserver.py and mentioned PyCharm and the new VS Community]


comments powered by Disqus
 › 2017
 › Avoyd Editor Prototype
 › 2016
 › Black triangles and Peter Highspot
 › Colour palettes and lighting
 › Concept art by Rebecca Michalak
 › 2015
 › Internals of a lightweight task scheduler
 › Implementing a lightweight task scheduler
 › Feral Vector
 › Normal generation in the pixel shader
 › 2014
 › Python Google App Engine debugging with PyCharm CE
 › Lighting voxel octrees and procedural texturing
 › Patterns and spheres
 ›› Python Google App Engine debugging with PyTools 
 › Interview
 › Domain masking using Google App Engine
 › Octree streaming - part 4
 › Black triangles and nervous_testpilot
 › Presskit for Google App Engine
 › Octree streaming - part 3
 › Octree streaming - part 2
 › Octree streaming
 › 2013
 › LAN discovery with multiple adapters
 › Playing with material worlds
 › Developer Diary archive
 › Website redesign
 › First Person Editor
 › First Avoyd tech update video
 › Implementing a static website in Google App Engine
 › Multiplayer editing
 › First screenshots
 › Thoughts on gameplay modes
 › Back in 1999
 › 2002
 › ECTS 2002
 › Avoyd Version 1.6.1 out
 › Avoyd Version 1.6 out
 › 2001
 › Biting the bullet
 › Avoyd version 1.5 out
 › Monday Mayhem
 › Avoyd version 1.5 alpha 1 out
 › Avoyd version 1.4 out
 › ECTS 2001
 › Fun with Greek letters
 › Closer just a little closer
 › Back already
 › Artificial Humanity
 › Products and promises
 › Ecommerce
 › Explosions galore
 › Spring fixes
 › Open source and ports to other operating systems
 › Avoyd LAN Demo Version 1.1 is out
 › Thanks for the support
 › Avoyd LAN Demo Ready
 › Game Tech
 › Internals of a lightweight task scheduler
 › Implementing a lightweight task scheduler
 › Normal generation in the pixel shader
 › Lighting voxel octrees and procedural texturing
 › Octree streaming - part 4
 › Octree streaming - part 3
 › Octree streaming - part 2
 › Octree streaming
 › LAN discovery with multiple adapters
 › enkiTS
 › Internals of a lightweight task scheduler
 › Implementing a lightweight task scheduler
 › Web Tech
 › Python Google App Engine debugging with PyCharm CE
 ›› Python Google App Engine debugging with PyTools 
 › Domain masking using Google App Engine
 › Presskit for Google App Engine
 › Implementing a static website in Google App Engine
 › Avoyd
 › Avoyd Editor Prototype
 › Black triangles and Peter Highspot
 › Colour palettes and lighting
 › Concept art by Rebecca Michalak
 › Feral Vector
 › Patterns and spheres
 › Interview
 › Black triangles and nervous_testpilot
 › Playing with material worlds
 › Website redesign
 › First Person Editor
 › First Avoyd tech update video
 › Multiplayer editing
 › First screenshots
 › Thoughts on gameplay modes
 › Back in 1999
 › Avoyd 1999
 › Developer Diary archive
 › Back in 1999
 › ECTS 2002
 › Avoyd Version 1.6.1 out
 › Avoyd Version 1.6 out
 › Biting the bullet
 › Avoyd version 1.5 out
 › Monday Mayhem
 › Avoyd version 1.5 alpha 1 out
 › Avoyd version 1.4 out
 › ECTS 2001
 › Fun with Greek letters
 › Closer just a little closer
 › Back already
 › Artificial Humanity
 › Products and promises
 › Ecommerce
 › Explosions galore
 › Spring fixes
 › Open source and ports to other operating systems
 › Avoyd LAN Demo Version 1.1 is out
 › Thanks for the support
 › Avoyd LAN Demo Ready