script_helper: kill the subprocess on error
If Popen.communicate() raises an exception, kill the child process to not leave a running child process in background and maybe create a zombi process. This change fixes a ResourceWarning in Python 3.6 when unit tests are interrupted by CTRL+c.
This commit is contained in:
parent
6423429325
commit
7e6977a8bc
|
@ -83,16 +83,16 @@ def run_python_until_end(*args, **env_vars):
|
||||||
env = {}
|
env = {}
|
||||||
env.update(env_vars)
|
env.update(env_vars)
|
||||||
cmd_line.extend(args)
|
cmd_line.extend(args)
|
||||||
p = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
|
proc = subprocess.Popen(cmd_line, stdin=subprocess.PIPE,
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
||||||
env=env)
|
env=env)
|
||||||
|
with proc:
|
||||||
try:
|
try:
|
||||||
out, err = p.communicate()
|
out, err = proc.communicate()
|
||||||
finally:
|
finally:
|
||||||
|
proc.kill()
|
||||||
subprocess._cleanup()
|
subprocess._cleanup()
|
||||||
p.stdout.close()
|
rc = proc.returncode
|
||||||
p.stderr.close()
|
|
||||||
rc = p.returncode
|
|
||||||
err = strip_python_stderr(err)
|
err = strip_python_stderr(err)
|
||||||
return _PythonRunResult(rc, out, err), cmd_line
|
return _PythonRunResult(rc, out, err), cmd_line
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue