Traceback disapears before I can read it!

John Ladasky ladasky at my-deja.com
Sun May 11 16:53:23 EDT 2003


Hi, folks,

I'm not quite a newbie any more, but the world of Python is so large
that I can see myself asking naive questions for quite a while yet.

I'm using Python 2.2.2 on Win 2000 Pro.  I have written several
all-text apps using IDLE 0.8.  The time has come for me to graduate to
GUI apps.  I'm doing my development on my PC, but I can foresee the
need to run my applications on a Mac.  I've selected the wxPython
cross-platform GUI.

I quickly learned that IDLE's Tkinter-based GUI does not play nicely
with wxPython.  If I try to run a wxPython app from IDLE, I can crash
the system quite easily.  Therefore I'm trying to abandon IDLE.

Of course, I still need to see a traceback to debug my programs.  If I
invoke my wxPython app using PYTHON.EXE, I can get a stdout window,
which prints the traceback and any print statements that I might
include in my program.  So far, so good.  However, if an error
actually occurs, the stdout window closes immediately after printing
the traceback.  At the moment, my solution to this problem is to run
my wxPython app under IDLE, and hope that it doesn't crash before I
get to the part of the program that fails, so that I can read the
traceback.  Sloppy, I know.

Another solution to this problem might be to override the wxPython
event-handling method wxApp.OnExit, and insert an input (or readkey?
or EVT_KEY_DOWN handler?) statement that prompts "Press a key to
exit."  There are two problems with this.  One is that I might choose
to run my app using PYTHONW.EXE rather than PYTHON.EXE.  The former
doesn't have a stdout window, so the user won't see a prompt, even if
it exists.  And if there is no stdout window to get the focus, how
will it intercept the keyboard event anyway?  I'm worried that I will
leave many unterminated copies of my program in memory as I work.  Is
there a way that I can inform my program that the interpreter has a
stdout window open, and have it react accordingly?

Yet another solution might be to invoke a PyCrust shell from inside my
app.  I'm trying to figure out PyCrust.  So far, I've had little luck.
 I don't seem to be able to navigate the global namespace of my app
from a PyCrust window, as I would be able to to with IDLE.  Nor can I
get the stdout to be directed to the PyCrust window, which would allow
me to read the traceback.  Yes, I can read the traceback in the stdout
window that pops up with PYTHON.EXE.  Somehow that seems sloppy and
"wrong" to me.  I have a shell, so why shouldn't it intercept stdout?

O.K., all of you professional snake charmers, how do you debug in a
GUI environment?

--
John J. Ladasky Jr., Ph.D.
Department of Biology
Johns Hopkins University
Baltimore MD 21218
USA
Earth




More information about the Python-list mailing list