tests: properly close 'cat' child process on exit.

issue510
David Wilson 6 years ago
parent 174b685d16
commit 91513f5b7e

@ -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. # 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) proc = subprocess.Popen(
os.dup2(sys.stdout.fileno(), 1) 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 atexit.register(cleanup_travis_junk)
os.dup2(sys.stderr.fileno(), 2)
# ----------------- # -----------------
@ -54,7 +63,9 @@ def _argv(s, *args):
def run(s, *args, **kwargs): def run(s, *args, **kwargs):
argv = _argv(s, *args) argv = _argv(s, *args)
print('Running: %s' % (argv,)) 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): def get_output(s, *args, **kwargs):

Loading…
Cancel
Save