From 595e52bb5cad842045127d56a978bd59a98bd45b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciro=20Santilli=20=E5=85=AD=E5=9B=9B=E4=BA=8B=E4=BB=B6=20?= =?UTF-8?q?=E6=B3=95=E8=BD=AE=E5=8A=9F?= Date: Sun, 23 Sep 2018 19:03:14 +0100 Subject: [PATCH] run: try to overcome run BlockingIOError --- common.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common.py b/common.py index 671bc9a..2c20e18 100644 --- a/common.py +++ b/common.py @@ -397,6 +397,7 @@ def run_cmd( # Ignoring the exception is not enough as it prints a warning anyways. #sigpipe_old = signal.getsignal(signal.SIGPIPE) #signal.signal(signal.SIGPIPE, signal.SIG_DFL) + # https://stackoverflow.com/questions/15535240/python-popen-write-to-stdout-and-log-file-simultaneously/52090802#52090802 with subprocess.Popen(cmd, stdout=stdout, stderr=stderr, env=env, **kwargs) as proc: if out_file is not None: @@ -407,7 +408,11 @@ def run_cmd( if byte: if show_stdout: sys.stdout.buffer.write(byte) - sys.stdout.flush() + try: + sys.stdout.flush() + except BlockingIOError: + # TODO understand. Why, Python, why. + pass logfile.write(byte) else: break