PyQt5 失败并显示神秘消息 [英] PyQt5 fails with cryptic message

查看:68
本文介绍了PyQt5 失败并显示神秘消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了带有模型和视图的小应用程序.从一开始,每次出现问题时 PyQt5 都会崩溃
进程已完成,退出代码为 -1073740791 (0xC0000409)
它非常神秘.我不知道哪个组件失败了.有一段时间我能够通过调试解决这个问题,但有些失败,我不知道是什么.

I've created small app with model and view. Since the beginning PyQt5 crash each time something went wrong with
Process finished with exit code -1073740791 (0xC0000409)
Its extremely cryptic. I don't know which component failed. For some time I was able to solve this problem with debugging, but something failed and I don't know what.

如何从 PyQt5 获取调用堆栈?如何获得更详细的崩溃消息?

How to get call stack from PyQt5? How to get more verbose crash messages?

Python 3.6.1PyQt5 5.8.1PyCharm

Python 3.6.1 PyQt5 5.8.1 PyCharm

推荐答案

通过将 NVIDIA 驱动程序 回滚到以前的版本,设法修复了该问题.我使用的是 378.49 版本并切换回 376.33,现在一切正常.无论您使用何种显卡,您都可以尝试一下.

Managed to fix it by rolling back your NVIDIA Driver to the previous version. I was on version 378.49 and switched back to 376.33 and now everything works fine. You can give that a try regardless of your graphics card.

GTX 965M 示例:

转到设备管理器 -> 显示适配器 -> NVIDIA GeForce GTX 965M(右键单击)-> 属性-> 驱动程序选项卡-> 回滚驱动程序.

Go to Device Manager -> Display adapters -> NVIDIA GeForce GTX 965M (Right Click) -> Properties -> Driver tab -> Roll Back Driver.

注意:

有一个新版本的 Nvidia 驱动程序 (378.66).与 guru3d 的驱动程序相比 - 您拥有来自原始供应商的驱动程序和最新的修复程序.:)

There is a new version of the Nvidia driver (378.66). Comparing to the driver from guru3d - you have the driver from the original vendor and with newest fixes. :)

我已经在我的笔记本电脑上测试了这个版本(使用 GeForce GTX 960M).

I have tested this version on my laptop (with GeForce GTX 960M).

它在环境控制台上以退出代码 0 启动、运行和结束.现在好像可以了.

It starts, works and finishes with exit code 0 on the environment console. It seems to be ok now.

以下是 Nvidia 自他们的驱动程序有问题的 (378.49) 版本以来发生的变化:

Here is what Nvidia changed since the buggy (378.49) version of their driver:

(取自 http://us.download.nvidia.com/Windows/378.66/378.66-win10-win8-win7-notebook-release-notes.pdf,第 15 页)

(taken from http://us.download.nvidia.com/Windows/378.66/378.66-win10-win8-win7-notebook-release-notes.pdf, page 15)

更新:

我处理过同样的问题,答案是双重的:

I have dealt with the same problem, and the answer is twofold:

  1. 它崩溃的原因可能有多种.这可能是一个编程错误,调用了一个不存在的函数,传递了一个小部件而不是一个布局,等等.但是由于您没有得到有用的输出,您不知道去哪里寻找罪魁祸首.
  2. PyQT 会引发和捕获异常,但不会传递它们.相反,它只是以状态 1 退出以显示异常被捕获.

要捕获异常,您需要覆盖 sys 异常处理程序:

To catch the exceptions, you need to overwrite the sys exception handler:

# Back up the reference to the exceptionhook
sys._excepthook = sys.excepthook

def my_exception_hook(exctype, value, traceback):
    # Print the error and traceback
    print(exctype, value, traceback)
    # Call the normal Exception hook after
    sys._excepthook(exctype, value, traceback)
    sys.exit(1)

# Set the exception hook to our wrapping function
sys.excepthook = my_exception_hook

然后在您的执行代码中,将其包装在 try/catch 中.

Then in your execution code, wrap it in a try/catch.

try:
    sys.exit(app.exec_())
except:
    print("Exiting")

这篇关于PyQt5 失败并显示神秘消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆