Commit bf2a09d4 authored by Jérome Perrin's avatar Jérome Perrin

util/testnode/ProcessManager: explicitly close file descriptors

this prevent ResourceWarnings on python3
parent fb38562e
...@@ -136,8 +136,6 @@ def killCommand(pid): ...@@ -136,8 +136,6 @@ def killCommand(pid):
class ProcessManager(object): class ProcessManager(object):
stdin = open(os.devnull)
def __init__(self, max_timeout=MAX_TIMEOUT): def __init__(self, max_timeout=MAX_TIMEOUT):
self.process_pid_set = set() self.process_pid_set = set()
signal.signal(signal.SIGTERM, self.sigterm_handler) signal.signal(signal.SIGTERM, self.sigterm_handler)
...@@ -176,7 +174,9 @@ class ProcessManager(object): ...@@ -176,7 +174,9 @@ class ProcessManager(object):
logger.info('subprocess_kw : %r', subprocess_kw) logger.info('subprocess_kw : %r', subprocess_kw)
logger.info('$ %s', command) logger.info('$ %s', command)
sys.stdout.flush() sys.stdout.flush()
p = subprocess.Popen(args, stdin=self.stdin, stdout=subprocess.PIPE,
with open(os.devnull) as stdin:
p = subprocess.Popen(args, stdin=stdin, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, env=env, close_fds=True, stderr=subprocess.PIPE, env=env, close_fds=True,
**subprocess_kw) **subprocess_kw)
self.process_pid_set.add(p.pid) self.process_pid_set.add(p.pid)
...@@ -189,6 +189,9 @@ class ProcessManager(object): ...@@ -189,6 +189,9 @@ class ProcessManager(object):
result = dict(status_code=p.returncode, command=command, result = dict(status_code=p.returncode, command=command,
stdout=stdout, stderr=stderr) stdout=stdout, stderr=stderr)
self.process_pid_set.discard(p.pid) self.process_pid_set.discard(p.pid)
p.stdout.close()
p.stderr.close()
if self.under_cancellation: if self.under_cancellation:
raise CancellationError("Test Result was cancelled") raise CancellationError("Test Result was cancelled")
if raise_error_if_fail and p.returncode: if raise_error_if_fail and p.returncode:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment