views:

201

answers:

2

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

+2  A: 

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.

Nazarius Kappertaal
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.
Bryan Oakley
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.
Nazarius Kappertaal
+3  A: 

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.

Virgil Dupras