Skip to content

Commit

Permalink
fix(command_util): handle large prints to stderr
Browse files Browse the repository at this point in the history
This commit reverts the changes that are made in  231de91 and 064dbea

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 (9c1fd04#diff-ba32be4c87f001d23e893532290ec28a66c901ff8667d4d3f60d6630838de1e2) which has been working fine for the last year and adds an exception for the edge case which was failing.
  • Loading branch information
mostaphaRoudsari committed Dec 31, 2021
1 parent d2e7d54 commit 858df58
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions honeybee_radiance_command/_command_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 858df58

Please sign in to comment.