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):
super().__init__(sys.argv)
# Exit on exceptions
sys.excepthook = self._tmp_exception_hook
sys.excepthook = self._exception_hook
# Handle segfaults
faulthandler.enable()
@ -112,15 +111,6 @@ class QuteBrowser(QApplication):
for url in config.config.get('general', 'startpage').split(','):
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):
"""Handle uncaught python exceptions.
@ -130,7 +120,7 @@ class QuteBrowser(QApplication):
# pylint: disable=broad-except
exc = (exctype, excvalue, tb)
traceback.print_exception(*exc)
sys.__excepthook__(*exc)
pages = []
try:
@ -161,7 +151,7 @@ class QuteBrowser(QApplication):
logging.debug('Running {} with args {}'.format(sys.executable,
argv))
subprocess.Popen(argv)
self.exit(1)
sys.exit(1)
def _python_hacks(self):
"""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
Python interpreter once all 500ms.
"""
sys.excepthook = self._exception_hook
signal(SIGINT, lambda *args: self.exit(128 + SIGINT))
self.timer = QTimer()
self.timer.start(500)

View File

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