瀏覽代碼

Merge pull request #4621 from shin-/3880-handle-broken-pipe

Do not raise a broken pipe error when receiving SIGPIPE
Joffrey F 8 年之前
父節點
當前提交
73aff2b50f
共有 2 個文件被更改,包括 10 次插入0 次删除
  1. 1 0
      compose/cli/main.py
  2. 9 0
      compose/cli/signals.py

+ 1 - 0
compose/cli/main.py

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

+ 9 - 0
compose/cli/signals.py

@@ -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)