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.
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):

Loading…
Cancel
Save