Python has a wonderful interactive interpreter (i.e. shell). However, sometimes you need more setup before you can start coding. Previously, I wrote Python: Coding in the Debugger for Beginners.
Google App Engine works a bit like CGI in that output to STDOUT goes to the browser. This breaks my normal "import pdb; pdb.set_trace()" trick. However, it's not hard to put STDOUT, etc. back so that you can use pdb in the way you normally would:
Google App Engine works a bit like CGI in that output to STDOUT goes to the browser. This breaks my normal "import pdb; pdb.set_trace()" trick. However, it's not hard to put STDOUT, etc. back so that you can use pdb in the way you normally would:
for attr in ('stdin', 'stdout', 'stderr'):
setattr(sys, attr, getattr(sys, '__%s__' % attr))
import pdb
pdb.set_trace()
Comments
Haha, as usual, you're way ahead of me.
def set_trace():
import pdb, sys
debugger = pdb.Pdb(stdin=sys.__stdin__,
stdout=sys.__stdout__)
debugger.set_trace(sys._getframe().f_back)
This messes with Google's sandbox less.
Very helpful. Thanks!
Using whit537's method I get this shown in the browser:
BdbQuit at /stop/37023745/
Request Method: GET
Request URL: http://localhost:8080/stop/37023745/
Exception Type: BdbQuit
Exception Value:
Exception Location: /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/bdb.py in dispatch_call, line 80
Go to your apps parent directory and run "dev_appserver.py yourappname"
pdb.Pdb(stdin=getattr(sys,'__stdin__'),stdout=getattr(sys,'__stderr__')).set_trace(sys._getframe().f_back)
- the idea being leave stdout alone. Seems to work. I did not have any crap heading back toward the browser. Is there any best soln out there from someone who works on GAE (as a full time thing)?
Thanks.
> Is there any best soln out there from someone who works on GAE (as a full time thing)?
I have no clue.