Debugging App Engine application with Python pdb debugger

Python comes with command line debugger pdb which is a rough, but useful, tool for Python developers.

You can insert source code breakpoints by adding into your code….

import pdb ; pdb.set_trace()

… and next time the code is run an interactive pdb prompts opens in your terminal window.

Google App Engine captures stdout and stdin system input and output streams for its internal purposes. Since pdb relies on them, pdb cannot be directly opened in App Engine. You cannot open pdb at all on the App Engine production server, as the server is little bit special due to scalability goals (no raw file system, terminal access).

However, you can still open pdb() on your local App Engine development server with the following little trick:

def dbg():
 """ Enter pdb in App Engine

 Renable system streams for it.
 """
 import pdb
 import sys
 pdb.Pdb(stdin=getattr(sys,'__stdin__'),stdout=getattr(sys,'__stderr__')).set_trace(sys._getframe().f_back)

This will grab the real system input and output stream, launch pdb() with them and step back one stack frace before calling dbg(). So you can simply add a breakpoint to your App Engine like the following:

class MainPage(BasePage):
 """ Index page of the site.

 """

 def get(self):
   logging.debug("Loading main page")
   path = os.path.join(os.path.dirname(__file__), 'index.html')
   vars = self.get_vars()
   dbg() # inspect what template variables are being passed to the template
   self.response.out.write(template.render(path, vars))

How to actual use pdb and some more pdb goodies are documented in Plone collective maintained developer manual.

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+

Taking a screenshot on Samsung Galaxy S and other Samsung Android devices

Samsung Galaxy S comes with a internal screenshot capturing feature similar to iPhone. This is not the same as the infamous stock Android screenshot facility which forces you to turn on USB debugging, downloading Android SDK, etc. Captured screenshots can be found from Gallery in their own category ScreenCapture.

To take a screenshot

  • Hold Back touch key
  • Double press Home key

This feature is probably available on other Samsung Android devices, like Samsung Wildfire and Samsung Galaxy Tab.

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+

Qt on Android

I gave the Qt on Android project a try and was happily surprised how easy it was to get everything set up and get my QML Physics project running on Android phone without too much fuss. There was just one issue. Now I can continue the project again, and this time I even have proper device to work with 😉

Actually this is even better than before. While developing for Symbian or Meego, I always had a cloud of uncertainty hanging over my head. My experience with Symbian had taught me to be very skeptical about the platform and Meego devices weren’t out yet(and still aren’t ). And as everybody knows, those fears got some justification by Nokia. Maybe Meego will prevail, but I’m pretty sure Android is not going to disappear very soon.

WebGL on Android WebKit browser demoed by Sony

This definitely looks promising.

3D accelerated effects are no longer the monopoly of desktop beta browsers (Firefox 4, Google Chrome 9… I am looking at you). Sony demoes Javascript WebGL on its Xperia handset. WebGL would be major turning point for mobile gaming, as it would lower the barrier of enty for building cross-platform mobile games.

Not just games, but the whole web user experience will be redefined when you can finally push impressive visuals to the site visitors.

I can so see the demo scene of 90s coming back soon…

\"\" Subscribe to RSS feed Follow me on Twitter Follow me on Facebook Follow me Google+