Crash more reliably #2

This commit is contained in:
Florian Bruhin 2014-02-06 10:25:22 +01:00
parent ae81427293
commit 9a0451c984
2 changed files with 17 additions and 27 deletions

View File

@ -44,8 +44,7 @@ class QuteBrowser(QApplication):
def __init__(self): def __init__(self):
super().__init__(sys.argv) super().__init__(sys.argv)
# Exit on exceptions sys.excepthook = self._exception_hook
sys.excepthook = self._tmp_exception_hook
# Handle segfaults # Handle segfaults
faulthandler.enable() faulthandler.enable()
@ -112,15 +111,6 @@ class QuteBrowser(QApplication):
for url in config.config.get('general', 'startpage').split(','): for url in config.config.get('general', 'startpage').split(','):
self.mainwindow.tabs.tabopen(url) self.mainwindow.tabs.tabopen(url)
def _tmp_exception_hook(self, exctype, excvalue, tb):
"""Handle exceptions while initializing by simply exiting.
This is only temporary and will get replaced by exception_hook later.
It's necessary because PyQt seems to ignore exceptions by default.
"""
sys.__excepthook__(exctype, excvalue, tb)
self.exit(1)
def _exception_hook(self, exctype, excvalue, tb): def _exception_hook(self, exctype, excvalue, tb):
"""Handle uncaught python exceptions. """Handle uncaught python exceptions.
@ -130,7 +120,7 @@ class QuteBrowser(QApplication):
# pylint: disable=broad-except # pylint: disable=broad-except
exc = (exctype, excvalue, tb) exc = (exctype, excvalue, tb)
traceback.print_exception(*exc) sys.__excepthook__(*exc)
pages = [] pages = []
try: try:
@ -161,7 +151,7 @@ class QuteBrowser(QApplication):
logging.debug('Running {} with args {}'.format(sys.executable, logging.debug('Running {} with args {}'.format(sys.executable,
argv)) argv))
subprocess.Popen(argv) subprocess.Popen(argv)
self.exit(1) sys.exit(1)
def _python_hacks(self): def _python_hacks(self):
"""Get around some PyQt-oddities by evil hacks. """Get around some PyQt-oddities by evil hacks.
@ -170,7 +160,6 @@ class QuteBrowser(QApplication):
exit status, and handles Ctrl+C properly by passing control to the exit status, and handles Ctrl+C properly by passing control to the
Python interpreter once all 500ms. Python interpreter once all 500ms.
""" """
sys.excepthook = self._exception_hook
signal(SIGINT, lambda *args: self.exit(128 + SIGINT)) signal(SIGINT, lambda *args: self.exit(128 + SIGINT))
self.timer = QTimer() self.timer = QTimer()
self.timer.start(500) self.timer.start(500)

View File

@ -20,14 +20,14 @@ class CrashDialog(QDialog):
vbox = QVBoxLayout() vbox = QVBoxLayout()
lbl = QLabel(self) lbl = QLabel(self)
lbl.setText( text = ('Argh! qutebrowser crashed unexpectedly.<br/>'
'Argh! qutebrowser crashed unexpectedly.<br/>' 'Please review the info below to remove sensitive data and '
'Please review the info below to remove sensitive data and then ' 'then submit it to <a href="mailto:crash@qutebrowser.org">'
'submit it to <a href="mailto:crash@qutebrowser.org">' 'crash@qutebrowser.org</a>.<br/><br/>')
'crash@qutebrowser.org</a>.<br/><br/>' if pages:
'You can click "Restore tabs" to attempt to reopen your ' text += ('You can click "Restore tabs" to attempt to reopen your '
'open tabs.' 'open tabs.')
) lbl.setText(text)
lbl.setWordWrap(True) lbl.setWordWrap(True)
vbox.addWidget(lbl) vbox.addWidget(lbl)
@ -55,6 +55,7 @@ class CrashDialog(QDialog):
btn_quit.setText('Quit') btn_quit.setText('Quit')
btn_quit.clicked.connect(self.reject) btn_quit.clicked.connect(self.reject)
hbox.addWidget(btn_quit) hbox.addWidget(btn_quit)
if pages:
btn_restore = QPushButton(self) btn_restore = QPushButton(self)
btn_restore.setText('Restore tabs') btn_restore.setText('Restore tabs')
btn_restore.clicked.connect(self.accept) btn_restore.clicked.connect(self.accept)