summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2021-10-25 12:56:07 +0200
committerFlorian Bruhin <me@the-compiler.org>2021-10-25 12:59:24 +0200
commitd59ed9400395bbe3563246615ef18730aaaac747 (patch)
tree295e779377991698f80dbba46f7453af37ea5d32
parent36ffff2f6b3b77f900cd503b86ec9cfd9497e983 (diff)
downloadqutebrowser-d59ed9400395bbe3563246615ef18730aaaac747.tar.gz
qutebrowser-d59ed9400395bbe3563246615ef18730aaaac747.zip
Improve error handling with early faulthandler enable
Speculative fix for issue reported by a macOS user: https://crashes.qutebrowser.org/lists?search=NullWriter See https://github.com/pyinstaller/pyinstaller/issues/4481 (cherry picked from commit ed5af1fcd2b37f12a424e5d5d9b4e57ac331fe2a)
-rw-r--r--qutebrowser/misc/earlyinit.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/qutebrowser/misc/earlyinit.py b/qutebrowser/misc/earlyinit.py
index c4ff0bb85..1863dedb3 100644
--- a/qutebrowser/misc/earlyinit.py
+++ b/qutebrowser/misc/earlyinit.py
@@ -111,17 +111,21 @@ def init_faulthandler(fileobj=sys.__stderr__):
Args:
fobj: An opened file object to write the traceback to.
"""
- if fileobj is None:
+ try:
+ faulthandler.enable(fileobj)
+ except (RuntimeError, AttributeError) as e:
# When run with pythonw.exe, sys.__stderr__ can be None:
# https://docs.python.org/3/library/sys.html#sys.__stderr__
- # If we'd enable faulthandler in that case, we just get a weird
- # exception, so we don't enable faulthandler if we have no stdout.
+ #
+ # With PyInstaller, it can be a NullWriter raising AttributeError on
+ # fileno: https://github.com/pyinstaller/pyinstaller/issues/4481
#
# Later when we have our data dir available we re-enable faulthandler
# to write to a file so we can display a crash to the user at the next
# start.
+ log.debug(f"Failed to enable early faulthandler: {e}", exc_info=True)
return
- faulthandler.enable(fileobj)
+
if (hasattr(faulthandler, 'register') and hasattr(signal, 'SIGUSR1') and
sys.stderr is not None):
# If available, we also want a traceback on SIGUSR1.