python程序员报告,Python中的崩溃报告

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:

5b743b1fb6481f1ff3ebad89c4bd30d5.png

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值