From 91513f5b7ee32f316f61f64fc9b6b01cbaac8858 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 5 Nov 2018 12:39:39 +0000 Subject: [PATCH] tests: properly close 'cat' child process on exit. --- .travis/ci_lib.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.travis/ci_lib.py b/.travis/ci_lib.py index e92564b6..d8d6827d 100644 --- a/.travis/ci_lib.py +++ b/.travis/ci_lib.py @@ -37,11 +37,20 @@ if not hasattr(subprocess, 'check_output'): # Force stdout FD 1 to be a pipe, so tools like pip don't spam progress bars. -sys.stdout = os.popen('stdbuf -oL cat', 'w', 1) -os.dup2(sys.stdout.fileno(), 1) +proc = subprocess.Popen( + args=['stdbuf', '-oL', 'cat'], + stdin=subprocess.PIPE +) + +os.dup2(proc.stdin.fileno(), 1) +os.dup2(proc.stdin.fileno(), 2) + +def cleanup_travis_junk(): + sys.stdout.close() + sys.stderr.close() + proc.terminate() -sys.stderr = sys.stdout -os.dup2(sys.stderr.fileno(), 2) +atexit.register(cleanup_travis_junk) # ----------------- @@ -54,7 +63,9 @@ def _argv(s, *args): def run(s, *args, **kwargs): argv = _argv(s, *args) print('Running: %s' % (argv,)) - return subprocess.check_call(argv, **kwargs) + ret = subprocess.check_call(argv, **kwargs) + print('Finished running: %s' % (argv,)) + return ret def get_output(s, *args, **kwargs):