简体   繁体   English

PyQt5失败了,含有神秘的信息

[英]PyQt5 fails with cryptic message

I've created small app with model and view. 我用模型和视图创建了小应用程序。 Since the beginning PyQt5 crash each time something went wrong with 从一开始PyQt5每次出错都会崩溃
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. 有一段时间我能通过调试解决这个问题,但有些事情失败了,我不知道是什么。

How to get call stack from PyQt5? 如何从PyQt5获取调用堆栈? How to get more verbose crash messages? 如何获得更详细的崩溃消息?

Python 3.6.1 PyQt5 5.8.1 PyCharm Python 3.6.1 PyQt5 5.8.1 PyCharm

Managed to fix it by rolling back your NVIDIA Driver to the previous version. 通过将NVIDIA驱动程序回滚到以前的版本来管理修复它。 I was on version 378.49 and switched back to 376.33 and now everything works fine. 我在版本378.49并切换回376.33现在一切正常。 You can give that a try regardless of your graphics card. 无论您的显卡如何,都可以尝试一下。

Example with GTX 965M : GTX 965M示例:

Go to Device Manager -> Display adapters -> NVIDIA GeForce GTX 965M (Right Click) -> Properties -> Driver tab -> Roll Back Driver. 转到设备管理器 - >显示适配器 - > NVIDIA GeForce GTX 965M(右键单击) - >属性 - >驱动程序选项卡 - >回滚驱动程序。

Note: 注意:

There is a new version of the Nvidia driver (378.66) . 有一个新版本的Nvidia驱动程序(378.66) Comparing to the driver from guru3d - you have the driver from the original vendor and with newest fixes. guru3d的驱动程序相比 - 您拥有原始供应商的驱动程序和最新的修复程序。 :) :)

I have tested this version on my laptop (with GeForce GTX 960M ). 我在笔记本电脑上测试了这个版本(使用GeForce GTX 960M )。

It starts, works and finishes with exit code 0 on the environment console. 它在环境控制台上以退出代码0启动,工作和完成。 It seems to be ok now. 现在似乎还可以。

Here is what Nvidia changed since the buggy (378.49) version of their driver: 以下是Nvidia自其驱动程序的bug (378.49)版本以来的变化:

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

Updated: 更新:

I have dealt with the same problem, and the answer is twofold: 我处理过同样的问题,答案是双重的:

  1. The reason it's crashing could be any number of things. 崩溃的原因可能是任何事情。 It's probably a programming bug, calling a function that doesn't exist, passing a widget instead of a layout, etc. But since you're not getting the useful output you don't know where to look for the culprit. 它可能是一个编程错误,调用一个不存在的函数,传递一个小部件而不是一个布局等等。但是由于你没有得到有用的输出,你不知道在哪里寻找罪魁祸首。
  2. PyQT raises and catches exceptions, but doesn't pass them along. PyQT引发并捕获异常,但不会传递它们。 Instead, it just exits with a status of 1 to show an exception was caught. 相反,它只是退出状态为1以显示异常被捕获。

To catch the exceptions, you need to overwrite the sys exception handler: 要捕获异常,您需要覆盖sys异常处理程序:

# 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

Then in your execution code, wrap it in a try/catch. 然后在执行代码中,将其包装在try / catch中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM