summaryrefslogtreecommitdiff
path: root/lib/spack/llnl/util/tty/log.py
diff options
context:
space:
mode:
authoralalazo <massimiliano.culpo@googlemail.com>2016-07-13 20:49:16 +0200
committeralalazo <massimiliano.culpo@googlemail.com>2016-07-13 22:50:39 +0200
commit90b131260bc04b0cdd2caf3959c970bb9fbc69fb (patch)
tree3de4fb53cd997ffdc58873624d868922d8d2361c /lib/spack/llnl/util/tty/log.py
parent7cedd620f1e233e559879dbb84d23db52a1a4a3c (diff)
downloadspack-90b131260bc04b0cdd2caf3959c970bb9fbc69fb.tar.gz
spack-90b131260bc04b0cdd2caf3959c970bb9fbc69fb.tar.bz2
spack-90b131260bc04b0cdd2caf3959c970bb9fbc69fb.tar.xz
spack-90b131260bc04b0cdd2caf3959c970bb9fbc69fb.zip
log : changed semantic for start / join (now it's explicit)
Diffstat (limited to 'lib/spack/llnl/util/tty/log.py')
-rw-r--r--lib/spack/llnl/util/tty/log.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/spack/llnl/util/tty/log.py b/lib/spack/llnl/util/tty/log.py
index 7f88261e34..4738c8981a 100644
--- a/lib/spack/llnl/util/tty/log.py
+++ b/lib/spack/llnl/util/tty/log.py
@@ -131,8 +131,16 @@ class log_output(object):
# Spawn a daemon that writes what it reads from a pipe
self.p = multiprocessing.Process(target=self._forward_redirected_pipe, args=(self.read,), name='logger_daemon')
self.p.daemon = True
+ # I just need this to communicate to un-summon the daemon
+ self.parent_pipe, self.child_pipe = multiprocessing.Pipe()
+
+ def acquire(self):
self.p.start()
+ def release(self):
+ self.parent_pipe.send(True)
+ self.p.join(60.0) # 1 minute to join the child
+
def __enter__(self):
"""Redirect output from the with block to a file.
@@ -165,6 +173,7 @@ class log_output(object):
if read_file in rlist:
line = read_file.readline()
if not line:
+ # For some reason we never reach this point...
break
# Echo to stdout if requested.
@@ -175,6 +184,9 @@ class log_output(object):
log_file.write(_strip(line))
log_file.flush()
+ if self.child_pipe.poll():
+ break
+
def _redirect_to_pipe(self, write):
try:
# Save old stdout and stderr
@@ -216,7 +228,6 @@ class log_output(object):
tty._debug = self._debug
def __del__(self):
- """Closes the pipes and joins the daemon"""
+ """Closes the pipes"""
os.close(self.write)
- self.p.join(60.0) # 1 minute to join the daemonic child
os.close(self.read)