[PyKDE] Re: How to capture python tracebacks?
Paul Felix
pef at fluent.com
Thu Sep 6 17:46:55 BST 2001
>
> Hello all,
>
> I'm trying to figure out a way to capture python traceback
> messages that are apparently caught in the pyqt event loop
> and issued to stdout.
>
> For example, in the attached sample program, I would like
> the tracebacks that occur when the 'Error' button is clicked
> to be displayed in the multi line edit as well as stdout.
>
> I thought about implementing the event loop in my PyQApplication
> sub-class but could not find enough info to do it. Has anyone
> else done this?
>
Hi Dave,
The low-level approach might be to install your own excepthook (see sys
module). For example, you can add the following function to your code:
def myExceptHook(type, value, tb):
import traceback, string
global multiLineEdit
sys.__excepthook__(type, value, tb)
lines = traceback.format_exception(type, value, tb)
multiLineEdit.append(string.join(lines))
Then you can install it in your main function perhaps just before calling
exec_loop:
sys.excepthook = myExceptHook
appTopLevel.exec_loop()
Hope that helps,
Paul
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pef.vcf
Type: text/x-vcard
Size: 241 bytes
Desc: Card for Paul Felix
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20010906/bea9c171/pef.vcf
More information about the PyQt
mailing list