Inspecting long running programs

Greg McFarlane gregm at iname.com
Wed Sep 8 21:10:34 EDT 1999


Has anyone had experience with doing interactive debugging of long
running programs?

For example, a gui is displaying some non-reproducible and unexpected
behaviour and you would like to inspect the state of the program to
help in tracking down what went wrong.  You need to do this without
restarting the program.

One way is to put hooks into the program which would enable it to be
debugged while running.  For a Tkinter program, you can register a Tcl
command which calls a python function which calls eval (or exec) on
its arguments.  Once this is registered, you can invoke it from
another program using the Tk "send" command.  For example, say this is
the program you want to debug.

==============================
import Tkinter
root = Tkinter.Tk()

# Set up tcl command hook to be used for debugging.
def debugEval(text):
    return eval(text)
root.tk.createcommand('debugEval', eval)

... Do useful stuff ...

root.mainloop()
==============================

Then from another python script, you can call into the other program
using something like this:

# Send "dir(Tkinter)" to the running python program.
root.tk.eval('send tk debugEval dir(Tkinter)')


If the program is not running Tkinter, but using select.select say,
you could create a "debug socket" which would listen for connections
and eval() any input received on that socket.  This would be a little
more work that the Tkinter method, but would give the same
functionality.

Has anyone done this?  Are there standard ways to inspect running
python programs?


-- 
Greg McFarlane:    INMS Telstra Australia (gregm at iname.com)
Today's forecast:  Sunny, with occasional cloudy periods and a chance
                   of precipitation in some areas.




More information about the Python-list mailing list