mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-23 13:20:23 -07:00
Merge pull request #14774 from lamby/ignore-epipe-when-flushing-stdout-stderr
Ignore EPIPE when flushing stdout stderr
This commit is contained in:
commit
347aa7b032
1 changed files with 13 additions and 4 deletions
|
@ -28,6 +28,7 @@ import time
|
||||||
import locale
|
import locale
|
||||||
import logging
|
import logging
|
||||||
import getpass
|
import getpass
|
||||||
|
import errno
|
||||||
from struct import unpack, pack
|
from struct import unpack, pack
|
||||||
from termios import TIOCGWINSZ
|
from termios import TIOCGWINSZ
|
||||||
from multiprocessing import Lock
|
from multiprocessing import Lock
|
||||||
|
@ -129,11 +130,19 @@ class Display:
|
||||||
msg2 = to_unicode(msg2, self._output_encoding(stderr=stderr))
|
msg2 = to_unicode(msg2, self._output_encoding(stderr=stderr))
|
||||||
|
|
||||||
if not stderr:
|
if not stderr:
|
||||||
sys.stdout.write(msg2)
|
fileobj = sys.stdout
|
||||||
sys.stdout.flush()
|
|
||||||
else:
|
else:
|
||||||
sys.stderr.write(msg2)
|
fileobj = sys.stderr
|
||||||
sys.stderr.flush()
|
|
||||||
|
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:
|
if logger and not screen_only:
|
||||||
msg2 = nocolor.lstrip(u'\n')
|
msg2 = nocolor.lstrip(u'\n')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue