From 858df588e8dd4c07121b88aac4cdfe6154b58664 Mon Sep 17 00:00:00 2001 From: Mostapha Date: Thu, 30 Dec 2021 21:57:24 -0500 Subject: [PATCH] fix(command_util): handle large prints to stderr This commit reverts the changes that are made in https://github.com/ladybug-tools/honeybee-radiance-command/commit/231de913d0ad2f743bf0f169d3104a98bcee7f50 and https://github.com/ladybug-tools/honeybee-radiance-command/commit/064dbea9079a2ca46810c8decc36ee080a0766d8 Radiance has a specific way of handling warnings and it can print large amount of data to stderr during the command execution which can result in the command hanging for ever. This change reverts back to this commit (https://github.com/ladybug-tools/honeybee-radiance-command/commit/9c1fd04a1e09782e5d502dbe13fe09b85f4a7d50#diff-ba32be4c87f001d23e893532290ec28a66c901ff8667d4d3f60d6630838de1e2) which has been working fine for the last year and adds an exception for the edge case which was failing. --- honeybee_radiance_command/_command_util.py | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/honeybee_radiance_command/_command_util.py b/honeybee_radiance_command/_command_util.py index adaf95be..20a96608 100644 --- a/honeybee_radiance_command/_command_util.py +++ b/honeybee_radiance_command/_command_util.py @@ -50,10 +50,22 @@ def run_command(input_command, env=None, cwd=None, mute=True): if not mute: print('running %s' % command) - process = subprocess.Popen( - command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, shell=True, env=g_env - ) + try: + process = subprocess.Popen( + command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, shell=True, env=g_env + ) + except Exception as e: + # this is an edge case that is happening for certain commands on Mac when + # the command is executed from inside IronPython 2.7 + # see: https://discourse.ladybug.tools/t/hdr-adjust-false-color-not-working-on-mac/16941/3 + if 'Cannot redirect stderr to stdout yet' in str(e): + process = subprocess.Popen( + command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, shell=True, env=g_env + ) + else: + raise ValueError(e) try: for line in iter(process.stdout.readline, STDOUT_CHECK): @@ -66,7 +78,7 @@ def run_command(input_command, env=None, cwd=None, mute=True): except Exception: # nothing in stdout pass - stdout, stderr = process.communicate() + _, stderr = process.communicate() rc = process.returncode if cwd: @@ -83,7 +95,7 @@ def run_command(input_command, env=None, cwd=None, mute=True): except Exception: # nothing in stderr pass - if isinstance(rc, int) and rc != 0: + if rc != 0: raise RuntimeError('None zero return code: %d' % rc) # only gets here is successful