简体   繁体   中英

Traceback missing when exception encountered in pyqt5 Code in eclipse(pydev)

This may be a slight repetition of an unanswered year old question from the past, but I'm hoping I can provide a bit more information and see it answered.

The issue is that once code enters PyQt5's loops any crash fails to cause the traceback to be displayed in the console or anywhere else that I am aware of, however Traceback is displayed with no issues if the same program is simply run from the command line using the exact same command as eclipse uses.

issue confirmed after a clean install of all listed components on separate computer.

build-env:
eclipse neon 4.6.3 - 64bit Java
pydev 5.8
python 3.6.1 64 OR 32 bit version
PyQt 5.8.2 - Installed via pip3

Here's a complete microprogram that demonstrates the issue, if i run it from the command line and click the button, I get a traceback, but I do not get one if the program is run, and the button pressed from within eclipse.

from PyQt5 import QtWidgets
import sys

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        self.btn = QtWidgets.QPushButton('text', self)
        self.btn.clicked.connect(self.handleButton)

    def handleButton(self):
        error_trigger


if __name__ == '__main__':
    print ("Start")
    app = QtWidgets.QApplication(sys.argv)
    #error_trigger
    myapp = MainWindow()
    myapp.show()
    sys.exit(app.exec_())

Is anyone aware of any known issues, or configuration options that would cause this behavior?

It took Alot of random browsing on the internet, but eventually found the code needed to work around the problem, posted here for reference for anyone else who has the same issue. Was obvious when i finally found it. ;)

from PyQt5 import QtCore
import traceback, sys


if QtCore.QT_VERSION >= 0x50501:
    def excepthook(type_, value, traceback_):
        traceback.print_exception(type_, value, traceback_)
        QtCore.qFatal('')
sys.excepthook = excepthook

Hope this helps others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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