IDL’s coolest feature (debuggin python)

My favourite thing about IDL is that if it encounters an error, it drops you in the middle of the program in the interpreter, so you can examine variables, try commands, and generally work your way out of the error. I’ve seen the following tip elsewhere before, but I’m posting it here mostly for my own reference. Thanks to infinite8s on the pyglet mailing list for this one:

in the main key_press function:

def on_key_press(self, symbol, modifiers):
if symbol == key.Q:
elif symbol == key.D:
import pdb

now if you run your game and hit d, you’ll be in dropped into the
debugger right after the call to set_trace() (so basically in the
middle of your event loop). From here you can usually walk the call
graph, and investigate things if need be, or set breakpoints, etc. If
you hit ‘c’ at the debugger prompt your program will continue running.
Of course, you probably want to remove this code when you finally
release your product :)


1 Comment »

  1. Naveen said

    Hi Andrew,

    The problem with my tip above is that it doesn’t drop you into the right place when you have an exception. Somebody posted a reply to my tip that lets you replace the default exception handler with onne that enters the debugger – also if you use ipython (a much nicer command line interpreter), you can run the program with debugging turned on, and when your code has an exception you’ll be dropped into the right spot.

RSS feed for comments on this post · TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: