From 499f0767da6d0eb92e97aece1dbd2bb1ead5ece7 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sat, 18 Oct 2014 23:46:24 +0200 Subject: [PATCH] Revert "Never delete crash log file." This reverts commit dcad41c92e8b5a6875e6b70b91c75f1374badf56. Shutdown segfaults still happen too often, and the crash log doesn't tell us anything useful... --- qutebrowser/app.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 6d10d6b6b..044efcef8 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -416,6 +416,23 @@ class Application(QApplication): pass state_config['geometry']['mainwindow'] = geom + def _destroy_crashlogfile(self): + """Clean up the crash log file and delete it.""" + if self._crashlogfile is None: + return + # We use sys.__stderr__ instead of sys.stderr here so this will still + # work when sys.stderr got replaced, e.g. by "Python Tools for Visual + # Studio". + if sys.__stderr__ is not None: + faulthandler.enable(sys.__stderr__) + else: + faulthandler.disable() + self._crashlogfile.close() + try: + os.remove(self._crashlogfile.name) + except (PermissionError, FileNotFoundError): + log.destroy.exception("Could not remove crash log!") + def _exception_hook(self, exctype, excvalue, tb): """Handle uncaught python exceptions. @@ -476,6 +493,7 @@ class Application(QApplication): # run in some undefined state, so we only do the most needed shutdown # here. qInstallMessageHandler(None) + self._destroy_crashlogfile() sys.exit(1) @cmdutils.register(instance='app', name=['quit', 'q']) @@ -694,6 +712,9 @@ class Application(QApplication): except AttributeError as e: log.destroy.warning("Could not save {}.".format(what)) log.destroy.debug(e) + # Re-enable faulthandler to stdout, then remove crash log + log.destroy.debug("Deactiving crash log...") + self._destroy_crashlogfile() # If we don't kill our custom handler here we might get segfaults log.destroy.debug("Deactiving message handler...") qInstallMessageHandler(None)