asking for the python debugger

48 views
Skip to first unread message

Mat

unread,
Jan 24, 2009, 1:48:25 AM1/24/09
to Google App Engine
Hi,
I really would like to use pdb as my main way to debug an old app that
I received from a third-party.
Does it have a way to enable it by modifying the dev server code?

Thanks

Antonin Hildebrand

unread,
Jan 24, 2009, 8:40:51 AM1/24/09
to Google App Engine
Hi Mat,

I'm using pdb with success.

1. in SDK comment out line: "sys.meta_path = [hook]" in
dev_appserver.py (Warning: this will disable hardened production-like
environment dev_appserver provides for your local app!)
2. use following code to put trace in your app:
def b():
import pdb, sys
sys.__stdout__.write('\a')
sys.__stdout__.flush()
debugger = pdb.Pdb(stdin=sys.__stdin__, stdout=sys.__stdout__)
debugger.set_trace(sys._getframe().f_back)

I have this function dbg module and small textmate snippet which puts:
import dbg;dbg.b() # where you want breakpoint

regards,
Antonin

Note: once I was able to use pdb without global sys.meta patch by
temporarily patching sys.meta in my main handler. This doesn't work
for me anymore (maybe some caching issues or some newly hardened parts
got into the way, I don't know I'm not a python pro)

You may also check FirePython for aid in debugging your app:
http://github.com/darwin/firepython/tree/master

Mat

unread,
Jan 24, 2009, 12:26:46 PM1/24/09
to Google App Engine
Hi Antonin,
when I am commenting the line suggested in the dev_appserver.py, I get
the following error message:

File "/home/mat/prog/google_appengine/google/appengine/tools/
dev_appserver.py", line 782, in __init__
raise IOError(errno.EACCES, 'file not accessible')
IOError: [Errno 13] file not accessible

In the gae sdk version 1.1.8, the line 782 refers to the init function
of a fake file. Should I bypass completely the test for a fake file?
If so, I get version conflicts with other libs.
This is getting really annoying, I really don't understand why pdb is
not available for the DEV side!

Thanks,
Mat

On Jan 24, 8:40 am, Antonin Hildebrand <antonin.hildebr...@gmail.com>
wrote:

Mat

unread,
Jan 24, 2009, 12:26:53 PM1/24/09
to Google App Engine
Hi Antonin,
when I am commenting the line suggested in the dev_appserver.py, I get
the following error message:

File "/home/mat/prog/google_appengine/google/appengine/tools/
dev_appserver.py", line 782, in __init__
raise IOError(errno.EACCES, 'file not accessible')
IOError: [Errno 13] file not accessible

In the gae sdk version 1.1.8, the line 782 refers to the init function
of a fake file. Should I bypass completely the test for a fake file?
If so, I get version conflicts with other libs.
This is getting really annoying, I really don't understand why pdb is
not available for the DEV side!

Thanks,
Mat

On Jan 24, 8:40 am, Antonin Hildebrand <antonin.hildebr...@gmail.com>
wrote:

Antonin Hildebrand

unread,
Jan 24, 2009, 12:36:57 PM1/24/09
to google-a...@googlegroups.com
Ah, you are right. I've also disabled external file checking:

--- google/appengine/tools/dev_appserver.py (revision 35)
+++ google/appengine/tools/dev_appserver.py (working copy)
@@ -749,6 +749,7 @@
Returns:
True if the file is accessible, False otherwise.
"""
+ return True
logical_filename = normcase(os.path.abspath(filename))


And for my further needs I've also enabled socket module and commented
out MAX_RUNTIME_RESPONSE_SIZE limit.

Attaching full patch.
regards,
Antonin
r35.patch

Mat

unread,
Jan 26, 2009, 3:47:43 PM1/26/09
to Google App Engine
Thanks Antonin,
I am almost there...
Now it is working only the "first pass" when I hit the server, all the
following requests will also raise the debugger but won't be able to
output in the shell.
Do you have an idea why?
Message has been deleted

Antonin Hildebrand

unread,
Jan 26, 2009, 4:20:19 PM1/26/09
to google-a...@googlegroups.com
Well, what do you mean by "output in the shell" ?

Do you see pdb prompt in terminal?
From pdb prompt you may inspect objects by typing "pp <something>"

If you want to print something to terminal during program execution,
you probably have to send it to the standard error like this:
import sys;sys.stderr.write('Hello!')
It depends on the way how you executed dev_appserver.py and if you did
any output redirections.

I would use logging module instead...

---
If you are on OSX, you may try to run this project and debug main():
http://github.com/darwin/drydrop/tree/master

add these lines into main() in drydrop_handler.py
import sys;sys.stderr.write('Hello from main!')
import drydrop.lib.dbg;drydrop.lib.dbg.b()

run:
rake edge_gae
rake

it starts dev server in new terminal window with title "DryApp",
go to http://localhost:8080/
and then see "DryApp" terminal tab

debugger works even without patching GAE SDK
hmm, strange

anyway, this may be good example, I've just tested it here on my machine
Antonin

Mat

unread,
Jan 26, 2009, 4:46:07 PM1/26/09
to Google App Engine
Let say I type:
(pdb)print "hello"
(pdb)

Nothing won't be displayed as in a standard pdb shell.

thanks,
Mathieu
Reply all
Reply to author
Forward
0 new messages