From ed5af1fcd2b37f12a424e5d5d9b4e57ac331fe2a Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 25 Oct 2021 12:56:07 +0200 Subject: 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 --- qutebrowser/misc/earlyinit.py | 12 ++++++++---- 1 file 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. -- cgit v1.2.3-54-g00ecf