Skip to content

Commit 867c9e4

Browse files
andrewesweetludoo
andauthored
Stop Windows hangs when last output is on stderr (#72)
* Stop Windows hangs when last output is on stderr Terraform CLI runs sometimes only produce output on stderr, or writes its final output to stderr. Tests for variable validation conditions and pre/post conditions often elicit this behaviour. On Windows 10 and Python 3.9, this leads to a hang. Line 714 (in this PR) is a blocking operation that will never be satisfied given no further standard output will be observed. This PR hacks around it when running on Windows by redirecting stderr to stdout. This truly is a hack, because later logic from line 724 onwards assumes `err` will contain stderr but will now always be empty. In practice, this seems to work on Windows OK. A better solution might be to do something like https://stackoverflow.com/a/4896288. This pushes my limited python-fu. * Fixed typo * Fix linting errors * Fix linting errors --------- Co-authored-by: Ludovico Magnocavallo <ludomagno@google.com>
1 parent a447abf commit 867c9e4

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

tftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,9 @@ def execute_command(self, cmd, *cmd_args):
706706
retcode = None
707707
full_output_lines = []
708708
try:
709+
stderr_mode = subprocess.STDOUT if os.name == 'nt' else subprocess.PIPE
709710
p = subprocess.Popen(cmdline, stdout=subprocess.PIPE,
710-
stderr=subprocess.PIPE, cwd=self.tfdir, env=self.env,
711+
stderr=stderr_mode, cwd=self.tfdir, env=self.env,
711712
universal_newlines=True, encoding='utf-8',
712713
errors='ignore')
713714
while True:

0 commit comments

Comments
 (0)