Merge pull request #14774 from lamby/ignore-epipe-when-flushing-stdout-stderr

Ignore EPIPE when flushing stdout stderr
This commit is contained in:
Brian Coca 2016-03-03 14:26:20 -05:00
commit 347aa7b032

View file

@ -28,6 +28,7 @@ import time
import locale
import logging
import getpass
import errno
from struct import unpack, pack
from termios import TIOCGWINSZ
from multiprocessing import Lock
@ -129,11 +130,19 @@ class Display:
msg2 = to_unicode(msg2, self._output_encoding(stderr=stderr))
if not stderr:
sys.stdout.write(msg2)
sys.stdout.flush()
fileobj = sys.stdout
else:
sys.stderr.write(msg2)
sys.stderr.flush()
fileobj = sys.stderr
fileobj.write(msg2)
try:
fileobj.flush()
except IOError as e:
# Ignore EPIPE in case fileobj has been prematurely closed, eg.
# when piping to "head -n1"
if e.errno != errno.EPIPE:
raise
if logger and not screen_only:
msg2 = nocolor.lstrip(u'\n')