From 1d87eee4d77713b1272997c67bc17451744f01a1 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 27 May 2016 14:48:46 +0200 Subject: [PATCH] Fix starting when sys.stderr is None --- CHANGELOG.asciidoc | 1 + qutebrowser/misc/earlyinit.py | 3 ++- tests/unit/misc/test_earlyinit.py | 33 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 tests/unit/misc/test_earlyinit.py diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index a58c1f62d..188a11735 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -66,6 +66,7 @@ Fixed - Fixed updating the tab index in the statusbar when opening a background tab - Fixed a crash when entering `:-- ` in the commandline - Fixed `:debug-console` with PyQt 5.6 +- Fixed qutebrowser not starting when `sys.stderr` is `None` v0.6.2 ------ diff --git a/qutebrowser/misc/earlyinit.py b/qutebrowser/misc/earlyinit.py index 7507bc59e..b863d63fd 100644 --- a/qutebrowser/misc/earlyinit.py +++ b/qutebrowser/misc/earlyinit.py @@ -123,7 +123,8 @@ def init_faulthandler(fileobj=sys.__stderr__): # start. return faulthandler.enable(fileobj) - if hasattr(faulthandler, 'register') and hasattr(signal, 'SIGUSR1'): + if (hasattr(faulthandler, 'register') and hasattr(signal, 'SIGUSR1') and + sys.stderr is not None): # If available, we also want a traceback on SIGUSR1. # pylint: disable=no-member,useless-suppression faulthandler.register(signal.SIGUSR1) diff --git a/tests/unit/misc/test_earlyinit.py b/tests/unit/misc/test_earlyinit.py new file mode 100644 index 000000000..2a5ba1933 --- /dev/null +++ b/tests/unit/misc/test_earlyinit.py @@ -0,0 +1,33 @@ +# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: + +# Copyright 2016 Florian Bruhin (The-Compiler) +# +# This file is part of qutebrowser. +# +# qutebrowser is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# qutebrowser is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with qutebrowser. If not, see . + +"""Test qutebrowser.misc.earlyinit.""" + +import sys + +import pytest + +from qutebrowser.misc import earlyinit + + +@pytest.mark.parametrize('attr', ['stderr', '__stderr__']) +def test_init_faulthandler_stderr_none(monkeypatch, attr): + """Make sure init_faulthandler works when sys.stderr/__stderr__ is None.""" + monkeypatch.setattr(sys, attr, None) + earlyinit.init_faulthandler()