PyQt5 fails with cryptic message

前端 未结 1 1820
北海茫月
北海茫月 2021-01-14 20:12

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 (0xC00

相关标签:
1条回答
  • 2021-01-14 20:41

    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.

    Example with GTX 965M:

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

    Note:

    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. :)

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

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

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

    (taken from http://us.download.nvidia.com/Windows/378.66/378.66-win10-win8-win7-notebook-release-notes.pdf, page 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. Instead, it just exits with a status of 1 to show an exception was caught.

    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
    

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

    try:
        sys.exit(app.exec_())
    except:
        print("Exiting")
    
    0 讨论(0)
提交回复
热议问题