2222 )
2323)
2424
25+ _print = print
26+ def print (* args , ** kwargs ):
27+ file = kwargs .get ('file' , sys .stdout )
28+ flush = kwargs .pop ('flush' , False )
29+ _print (* args , ** kwargs )
30+ if flush :
31+ file .flush ()
32+
2533
2634#
2735# check_output() monkeypatch cutpasted from testlib.py
@@ -71,24 +79,22 @@ def _argv(s, *args):
7179
7280
7381def run (s , * args , ** kwargs ):
74- """ Run a command, with arguments, and print timing information
82+ """ Run a command, with arguments
7583
7684 >>> rc = run('echo "%s %s"', 'foo', 'bar')
77- Running: ['/usr/bin/time', '--', ' echo', 'foo bar']
85+ Running: ['echo', 'foo bar']
7886 foo bar
79- 0.00user 0.00system 0:00.00elapsed ?%CPU (0avgtext+0avgdata 1964maxresident)k
80- 0inputs+0outputs (0major+71minor)pagefaults 0swaps
81- Finished running: ['/usr/bin/time', '--', 'echo', 'foo bar']
87+ Finished running: ['echo', 'foo bar']
8288 >>> rc
8389 0
8490 """
85- argv = [ '/usr/bin/time' , '--' ] + _argv (s , * args )
86- print ('Running: %s' % (argv ,))
91+ argv = _argv (s , * args )
92+ print ('Running: %s' % (argv ,), flush = True )
8793 try :
8894 ret = subprocess .check_call (argv , ** kwargs )
89- print ('Finished running: %s' % (argv ,))
95+ print ('Finished running: %s' % (argv ,), flush = True )
9096 except Exception :
91- print ('Exception occurred while running: %s' % (argv ,))
97+ print ('Exception occurred while running: %s' % (argv ,), file = sys . stderr , flush = True )
9298 raise
9399
94100 return ret
@@ -155,7 +161,7 @@ def get_output(s, *args, **kwargs):
155161 'foo bar\n '
156162 """
157163 argv = _argv (s , * args )
158- print ('Running: %s' % (argv ,))
164+ print ('Running: %s' % (argv ,), flush = True )
159165 return subprocess .check_output (argv , ** kwargs )
160166
161167
@@ -368,12 +374,10 @@ def start_containers(containers):
368374def verify_procs (hostname , old , new ):
369375 oldpids = set (pid for pid , _ in old )
370376 if any (pid not in oldpids for pid , _ in new ):
371- print ('%r had stray processes running:' % (hostname ,))
377+ print ('%r had stray processes running:' % (hostname ,), file = sys . stderr , flush = True )
372378 for pid , line in new :
373379 if pid not in oldpids :
374- print ('New process:' , line )
375-
376- print ()
380+ print ('New process:' , line , flush = True )
377381 return False
378382
379383 return True
@@ -397,13 +401,10 @@ def check_stray_processes(old, containers=None):
397401
398402
399403def dump_file (path ):
400- print ()
401- print ('--- %s ---' % (path ,))
402- print ()
404+ print ('--- %s ---' % (path ,), flush = True )
403405 with open (path , 'r' ) as fp :
404- print (fp .read ().rstrip ())
405- print ('---' )
406- print ()
406+ print (fp .read ().rstrip (), flush = True )
407+ print ('---' , flush = True )
407408
408409
409410# SSH passes these through to the container when run interactively, causing
0 commit comments