summaryrefslogtreecommitdiff
path: root/lib/spack/llnl/util/tty/log.py
diff options
context:
space:
mode:
authorJohn W. Parent <45471568+johnwparent@users.noreply.github.com>2022-04-26 15:56:13 -0400
committerGitHub <noreply@github.com>2022-04-26 12:56:13 -0700
commit83b91246b101a30f78f246fb40fa9df54a1e8403 (patch)
tree37226915423c7b5269d0a9ed7c7e7df3cfaec013 /lib/spack/llnl/util/tty/log.py
parent0f4b228effc7969826eb78215a5efb68a5f693a8 (diff)
downloadspack-83b91246b101a30f78f246fb40fa9df54a1e8403.tar.gz
spack-83b91246b101a30f78f246fb40fa9df54a1e8403.tar.bz2
spack-83b91246b101a30f78f246fb40fa9df54a1e8403.tar.xz
spack-83b91246b101a30f78f246fb40fa9df54a1e8403.zip
Windows: fix termination of process output redirection (#29923)
The parent thread in the process stdout redirection logic on Windows was closing a file that was being read in child thread, which lead to error-based termination of the reader thread. This updates the interaction to avoid the error.
Diffstat (limited to 'lib/spack/llnl/util/tty/log.py')
-rw-r--r--lib/spack/llnl/util/tty/log.py32
1 files changed, 16 insertions, 16 deletions
diff --git a/lib/spack/llnl/util/tty/log.py b/lib/spack/llnl/util/tty/log.py
index 544a9a6c48..51b9caa332 100644
--- a/lib/spack/llnl/util/tty/log.py
+++ b/lib/spack/llnl/util/tty/log.py
@@ -809,19 +809,23 @@ class winlog(object):
def background_reader(reader, echo_writer, _kill):
# for each line printed to logfile, read it
# if echo: write line to user
- while True:
- is_killed = _kill.wait(.1)
- self.stderr.flush()
- self.stdout.flush()
- line = reader.readline()
- while line:
- if self.echo:
- self.echo_writer.write('{0}'.format(line.decode()))
- self.echo_writer.flush()
+ try:
+ while True:
+ is_killed = _kill.wait(.1)
+ # Flush buffered build output to file
+ # stdout/err fds refer to log file
+ self.stderr.flush()
+ self.stdout.flush()
+
line = reader.readline()
+ if self.echo and line:
+ echo_writer.write('{0}'.format(line.decode()))
+ echo_writer.flush()
- if is_killed:
- break
+ if is_killed:
+ break
+ finally:
+ reader.close()
self._active = True
with replace_environment(self.env):
@@ -837,7 +841,6 @@ class winlog(object):
self._ioflag = False
else:
self.writer.close()
- self.reader.close()
self.echo_writer.flush()
self.stdout.flush()
self.stderr.flush()
@@ -853,10 +856,7 @@ class winlog(object):
if not self._active:
raise RuntimeError(
"Can't call force_echo() outside log_output region!")
- try:
- yield self
- finally:
- pass
+ yield
def _writer_daemon(stdin_multiprocess_fd, read_multiprocess_fd, write_fd, echo,