“sys.excepthook中的错误”PyQt5.10.1Python 3.6

时间:2018-06-05 07:38:45

标签: pyqt5 python-3.6

我的main.py中有一个自定义的sys.excepthook:

def application_exception_hook(type_, value, tb):
    lines = format_exception(type_, value, tb)
    for line in lines:
        print(line)
    sys.excepthook = sys._excepthook
    sys.exit(1)

sys._excepthook = sys.excepthook
sys.excepthook = application_exception_hook

如果出现未处理的异常,控制台输出为:

Traceback (most recent call last):
Error in sys.excepthook:
Traceback (most recent call last):


Original exception was:
Traceback (most recent call last):

...更换

    for line in lines:
        print(line)

...与...

    print(lines)

...给我这个输出:

['Traceback (most recent call last):\n', '  File "D:\\...\\framework.py", line 144, in openNesting\n    foo = 123 / 0\n', 'ZeroDivisionError: division by zero\n']Error in sys.excepthook:
Traceback (most recent call last):


Original exception was:
Traceback (most recent call last):

因此,在这两种情况下都存在“sys.excepthook中的错误”,而在第一种情况下,在打印出所有有趣的属性之前,错误已经出现。我想知道什么可能导致“sys.excepthook中的错误”以及我如何才能获得此输出:

Traceback (most recent call last):
File "D:\\...\\framework.py", line 144, in openNesting
foo = 123 / 0
ZeroDivisionError: division by zero

我找不到解决此特定问题的任何已解决的主题。

1 个答案:

答案 0 :(得分:0)

已解决:将stdout和stderr消息复制到QtTextEdit的方法中存在错误。手动跟踪后,现在一切都按预期工作。