From 46be3d68336594ca69aff68a460ea476d09bd2de Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Wed, 4 Mar 2015 22:36:17 -0800 Subject: [PATCH] Added a patch to silence warnings from Firefox. #21. --- rtv/utils.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/rtv/utils.py b/rtv/utils.py index bd4fb6a..bbae53d 100644 --- a/rtv/utils.py +++ b/rtv/utils.py @@ -4,6 +4,9 @@ import time import threading from curses import textpad from contextlib import contextmanager +import subprocess +from functools import partial +from types import MethodType from .errors import EscapePressed @@ -43,6 +46,17 @@ class Color(object): curses.init_pair(index, code[0], code[1]) setattr(cls, attr, curses.color_pair(index)) +def patch_popen(): + """ + Patch subprocess.Popen default behavior to redirect stdout + stderr to null. + This is a hack to stop the webbrowser from spewing errors in firefox. + """ + + # http://stackoverflow.com/a/13359757/2526287 + stdout = open(os.devnull, 'w') + func = partial(subprocess.Popen.__init__, + stdout=stdout, stderr=stdout, close_fds=True) + subprocess.Popen.__init__ = MethodType(func, None, subprocess.Popen) def text_input(window): """ @@ -201,6 +215,8 @@ def curses_session(): # Hide blinking cursor curses.curs_set(0) + patch_popen() + yield stdscr finally: