6

Is there a crash reporting framework that can be used for pure Python Tkinter applications? Ideally, it should work cross-platform.

Practically speaking, this is more of 'exception reporting' since the Python interpreter itself hardly crashes.

Here's a sample crash reporter:

alt text

asked Dec 26, 2009 at 20:57

2 Answers 2

7

Rather than polluting your code with try..except everywhere, you should just implement your own except hook by setting sys.excepthook. Here is an example:

import sys
import traceback
def install_excepthook():
 def my_excepthook(exctype, value, tb):
 s = ''.join(traceback.format_exception(exctype, value, tb))
 dialog = ErrorReportDialog(None, s)
 dialog.exec_()
 sys.excepthook = my_excepthook

Call install_exception() when your application starts.

ErrorReportDialog is a Qt dialog I've made. traceback.format_exception() will format argument passed to the except hook in the same way it does in Python's interpreter.

EDIT: I forgot to mention a little gotcha with that. It doesn't work with threads (well, at least it didn't last time I checked). For code running in another thread, you will need to wrap it in a try..except block.

answered Dec 28, 2009 at 20:27
Sign up to request clarification or add additional context in comments.

Comments

2

Stick try excepts everywhere your application can crash (I/O, networking etc.). Whenever an except is called, call a function that will kill the old window, spawn a new tkinter notification window, or a custom one with your error message.

Do a root.after to the new window and send your error report (urllib).

Put a restart button if you wish.

There is no crash reporting framework - as tkinter is not that type of GUI. It's pretty much a wrapper for simple command line apps.

Go pyqt/gtk or wxpython if you want the features seen in the screen-shot above. But I'm pretty sure that where ever you go, you'll have to write your own reporter.

answered Dec 28, 2009 at 6:25

2 Comments

I disagree with the statement that tkinter is "pretty much a wrapper for simple command line apps". Tkinter is a full fledged GUI library suitable for all sorts of purposes. And in fact, Tkinter can also be used to implement all the features in the screenshot.
I don't disagree, but if one were to make a full fledged, maintainable GUI (with crash reporting and threads), with the least amount of effort, one would use one of the other toolkits I listed above. The reason they exist is because Tkinter does not fulfil this need adequately.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.