How can I capture all exceptions from a wxPython application?

前端 未结 4 674
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-29 15:50

I\'m writing a little debug app for a bit of kit we\'re developing and I\'d like to roll it out to a few users to see if they can provoke any crashes. Does anyone know a way

4条回答
  •  清酒与你
    2020-12-29 16:21

    You can use

    sys.excepthook

    (see Python docs)

    and assign some custom object to it, that would catch all exceptions not caught earlier in your code. You can then log any message to any file you wish, together with traceback and do whatever you like with the exception (reraise it, display error message and allow user to continue using your app etc).

    As for logging stdout - the best way for me was to write something similar to DzinX's OutWrapper.

    If you're at debugging stage, consider flushing your log files after each entry. This harms performance a lot, but if you manage to cause segfault in some underlying C code, your logs won't mislead you.

提交回复
热议问题