From 9a0451c98499c74a9ee02560ff63e32079a639f5 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 6 Feb 2014 10:25:22 +0100 Subject: [PATCH] Crash more reliably #2 --- qutebrowser/app.py | 17 +++-------------- qutebrowser/widgets/__init__.py | 27 ++++++++++++++------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index b87ac0910..948cc6bb3 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -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) diff --git a/qutebrowser/widgets/__init__.py b/qutebrowser/widgets/__init__.py index a36ab3be3..eff29465d 100644 --- a/qutebrowser/widgets/__init__.py +++ b/qutebrowser/widgets/__init__.py @@ -20,14 +20,14 @@ class CrashDialog(QDialog): vbox = QVBoxLayout() lbl = QLabel(self) - lbl.setText( - 'Argh! qutebrowser crashed unexpectedly.
' - 'Please review the info below to remove sensitive data and then ' - 'submit it to ' - 'crash@qutebrowser.org.

' - 'You can click "Restore tabs" to attempt to reopen your ' - 'open tabs.' - ) + text = ('Argh! qutebrowser crashed unexpectedly.
' + 'Please review the info below to remove sensitive data and ' + 'then submit it to ' + 'crash@qutebrowser.org.

') + 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()