diff options
author | John W. Parent <45471568+johnwparent@users.noreply.github.com> | 2022-04-26 15:56:13 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-26 12:56:13 -0700 |
commit | 83b91246b101a30f78f246fb40fa9df54a1e8403 (patch) | |
tree | 37226915423c7b5269d0a9ed7c7e7df3cfaec013 /lib | |
parent | 0f4b228effc7969826eb78215a5efb68a5f693a8 (diff) | |
download | spack-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')
-rw-r--r-- | lib/spack/llnl/util/tty/log.py | 32 | ||||
-rw-r--r-- | lib/spack/spack/main.py | 13 |
2 files changed, 20 insertions, 25 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, diff --git a/lib/spack/spack/main.py b/lib/spack/spack/main.py index 5f13f0736f..feab2b6f81 100644 --- a/lib/spack/spack/main.py +++ b/lib/spack/spack/main.py @@ -30,7 +30,7 @@ import llnl.util.lang import llnl.util.tty as tty import llnl.util.tty.colify import llnl.util.tty.color as color -from llnl.util.tty.log import log_output, winlog +from llnl.util.tty.log import log_output import spack import spack.cmd @@ -605,14 +605,9 @@ class SpackCommand(object): out = StringIO() try: - if sys.platform == 'win32': - with winlog(out): - self.returncode = _invoke_command( - self.command, self.parser, args, unknown) - else: - with log_output(out): - self.returncode = _invoke_command( - self.command, self.parser, args, unknown) + with log_output(out): + self.returncode = _invoke_command( + self.command, self.parser, args, unknown) except SystemExit as e: self.returncode = e.code |