diff --git a/qutebrowser/app.py b/qutebrowser/app.py index ba8851b91..8d8696af9 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -19,6 +19,8 @@ ### Things we want to do before normal imports ### +import sys + # Print a nice traceback on segfault -- only available on Python 3.3+, but if # it's unavailable, it doesn't matter much. try: @@ -26,7 +28,16 @@ try: except ImportError: pass else: - faulthandler.enable() + if sys.__stdout__ is not None: + # When run with pythonw.exe, sys.__stdout__ can be None: + # https://docs.python.org/3/library/sys.html#sys.__stdout__ + # If we'd enable faulthandler in that case, we just get a weird + # exception, so we don't enable faulthandler in that case. + # + # FIXME at the point we have our config/data dirs, we probably should + # re-enable faulthandler to write to a file. Then we can also display + # crashes to the user at the next start. + faulthandler.enable() # See https://bugreports.qt-project.org/browse/QTBUG-36099 # We need to do this before importing PyQt @@ -37,8 +48,8 @@ harfbuzz.fix() import qutebrowser.utils.dependencies as dependencies dependencies.check() +# Early imports done, normal imports following now. import os -import sys import logging import subprocess import configparser diff --git a/qutebrowser/utils/debug.py b/qutebrowser/utils/debug.py index dbce1a079..c43a4fd62 100644 --- a/qutebrowser/utils/debug.py +++ b/qutebrowser/utils/debug.py @@ -56,7 +56,8 @@ def set_trace(): Based on http://stackoverflow.com/a/1745965/2085149 """ - sys.stdout.flush() + if sys.stdout is not None: + sys.stdout.flush() print() print("When done debugging, remember to execute:") print(" from PyQt5 import QtCore; QtCore.pyqtRestoreInputHook()") diff --git a/qutebrowser/utils/misc.py b/qutebrowser/utils/misc.py index 5c9880359..e50f9f6b0 100644 --- a/qutebrowser/utils/misc.py +++ b/qutebrowser/utils/misc.py @@ -167,7 +167,8 @@ def actute_warning(): with open('/usr/share/X11/locale/en_US.UTF-8/Compose', 'r') as f: for line in f: if '' in line: - sys.stdout.flush() + if sys.stdout is not None: + sys.stdout.flush() print("Note: If you got a 'dead_actute' warning above, that " "is not a bug in qutebrowser! See " "https://bugs.freedesktop.org/show_bug.cgi?id=69476 for "