Browse Source

Proper flushing of install logs

Fernando Correia 12 years ago
parent
commit
9f844f9af2
3 changed files with 18 additions and 1 deletions
  1. 1 1
      installer.py
  2. 4 0
      run-tests.py
  3. 13 0
      unbuffered.py

+ 1 - 1
installer.py

@@ -473,7 +473,7 @@ class Installer:
     except AttributeError:
       cwd = self.install_dir
 
-    print("\nRunning '%s' in %s" % (command, cwd))
+    print("\nINSTALL: Running '%s' in %s" % (command, cwd))
     if send_yes:
       process = subprocess.Popen(command, shell=True, stdin=subprocess.PIPE, cwd=cwd)
       process.communicate("yes")

+ 4 - 0
run-tests.py

@@ -1,11 +1,15 @@
 #!/usr/bin/env python
 import argparse
+import sys
 from benchmarker import Benchmarker
+from unbuffered import Unbuffered
 
 ###################################################################################################
 # Main
 ###################################################################################################
 
+sys.stdout=Unbuffered(sys.stdout)
+
 ##########################################################
 # Set up argument parser
 ##########################################################

+ 13 - 0
unbuffered.py

@@ -0,0 +1,13 @@
+# Wrapper for unbuffered stream writing.
+# http://stackoverflow.com/a/107717/376366
+# Used to make sure print output appears in the correct order
+# in log files when spawning subprocesses.
+
+class Unbuffered:
+  def __init__(self, stream):
+    self.stream = stream
+  def write(self, data):
+    self.stream.write(data)
+    self.stream.flush()
+  def __getattr__(self, attr):
+    return getattr(self.stream, attr)