Do not raise a broken pipe error when receiving SIGPIPE from grep or head

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-03-14 14:21:19 -07:00
parent dd294ce9cc
commit 56357d6117
2 changed files with 10 additions and 0 deletions

View File

@ -61,6 +61,7 @@ console_handler = logging.StreamHandler(sys.stderr)
def main():
signals.ignore_sigpipe()
try:
command = dispatch()
command()

View File

@ -3,6 +3,8 @@ from __future__ import unicode_literals
import signal
from ..const import IS_WINDOWS_PLATFORM
class ShutdownException(Exception):
pass
@ -19,3 +21,10 @@ def set_signal_handler(handler):
def set_signal_handler_to_shutdown():
set_signal_handler(shutdown)
def ignore_sigpipe():
# Restore default behavior for SIGPIPE instead of raising
# an exception when encountered.
if not IS_WINDOWS_PLATFORM:
signal.signal(signal.SIGPIPE, signal.SIG_DFL)