提交 2b4b3183 编写于 作者: L Lucas Meneghel Rodrigues

avocado.utils.process: Rename SubProcess.sp to SubProcess._popen

The reasoning here being that we don't want this part of
the public API. We don't need users to interact directly
with the Popen object, since the interaction will be
done by means of the public methods.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 69c8910d
...@@ -244,10 +244,10 @@ class SubProcess(object): ...@@ -244,10 +244,10 @@ class SubProcess(object):
self.verbose = verbose self.verbose = verbose
if self.verbose: if self.verbose:
log.info("Running '%s'", cmd) log.info("Running '%s'", cmd)
self.sp = subprocess.Popen(cmd, self._popen = subprocess.Popen(cmd,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
shell=True) shell=True)
self.allow_output_check = allow_output_check self.allow_output_check = allow_output_check
self.start_time = time.time() self.start_time = time.time()
self.result = CmdResult(cmd) self.result = CmdResult(cmd)
...@@ -256,12 +256,12 @@ class SubProcess(object): ...@@ -256,12 +256,12 @@ class SubProcess(object):
self.stdout_lock = threading.Lock() self.stdout_lock = threading.Lock()
self.stdout_thread = threading.Thread(target=self._fd_drainer, self.stdout_thread = threading.Thread(target=self._fd_drainer,
name="%s-stdout" % cmd, name="%s-stdout" % cmd,
args=[self.sp.stdout]) args=[self._popen.stdout])
self.stdout_thread.daemon = True self.stdout_thread.daemon = True
self.stderr_lock = threading.Lock() self.stderr_lock = threading.Lock()
self.stderr_thread = threading.Thread(target=self._fd_drainer, self.stderr_thread = threading.Thread(target=self._fd_drainer,
name="%s-stderr" % cmd, name="%s-stderr" % cmd,
args=[self.sp.stderr]) args=[self._popen.stderr])
self.stderr_thread.daemon = True self.stderr_thread.daemon = True
self.stdout_thread.start() self.stdout_thread.start()
self.stderr_thread.start() self.stderr_thread.start()
...@@ -286,7 +286,7 @@ class SubProcess(object): ...@@ -286,7 +286,7 @@ class SubProcess(object):
:param input_pipe: File like object to the stream. :param input_pipe: File like object to the stream.
""" """
stream_prefix = "%s" stream_prefix = "%s"
if input_pipe == self.sp.stdout: if input_pipe == self._popen.stdout:
prefix = '[stdout] %s' prefix = '[stdout] %s'
if self.allow_output_check in ['none', 'stderr']: if self.allow_output_check in ['none', 'stderr']:
stream_logger = None stream_logger = None
...@@ -294,7 +294,7 @@ class SubProcess(object): ...@@ -294,7 +294,7 @@ class SubProcess(object):
stream_logger = stdout_log stream_logger = stdout_log
output_file = self.stdout_file output_file = self.stdout_file
lock = self.stdout_lock lock = self.stdout_lock
elif input_pipe == self.sp.stderr: elif input_pipe == self._popen.stderr:
prefix = '[stderr] %s' prefix = '[stderr] %s'
if self.allow_output_check in ['none', 'stdout']: if self.allow_output_check in ['none', 'stdout']:
stream_logger = None stream_logger = None
...@@ -338,8 +338,8 @@ class SubProcess(object): ...@@ -338,8 +338,8 @@ class SubProcess(object):
self.stdout_thread.join() self.stdout_thread.join()
self.stderr_thread.join() self.stderr_thread.join()
# Clean subprocess pipes and populate stdout/err # Clean subprocess pipes and populate stdout/err
self.sp.stdout.close() self._popen.stdout.close()
self.sp.stderr.close() self._popen.stderr.close()
self.result.stdout = self.get_stdout() self.result.stdout = self.get_stdout()
self.result.stderr = self.get_stderr() self.result.stderr = self.get_stderr()
...@@ -385,13 +385,13 @@ class SubProcess(object): ...@@ -385,13 +385,13 @@ class SubProcess(object):
:param sig: Signal to send. :param sig: Signal to send.
""" """
self.sp.send_signal(sig) self._popen.send_signal(sig)
def poll(self): def poll(self):
""" """
Call the subprocess poll() method, fill results if rc is not None. Call the subprocess poll() method, fill results if rc is not None.
""" """
rc = self.sp.poll() rc = self._popen.poll()
if rc is not None: if rc is not None:
self._fill_results(rc) self._fill_results(rc)
return rc return rc
...@@ -400,7 +400,7 @@ class SubProcess(object): ...@@ -400,7 +400,7 @@ class SubProcess(object):
""" """
Call the subprocess poll() method, fill results if rc is not None. Call the subprocess poll() method, fill results if rc is not None.
""" """
rc = self.sp.wait() rc = self._popen.wait()
if rc is not None: if rc is not None:
self._fill_results(rc) self._fill_results(rc)
return rc return rc
...@@ -440,7 +440,7 @@ class SubProcess(object): ...@@ -440,7 +440,7 @@ class SubProcess(object):
self.poll() self.poll()
# If all this work fails, we're dealing with a zombie process. # If all this work fails, we're dealing with a zombie process.
e_msg = 'Zombie Process %s' % self.sp.pid e_msg = 'Zombie Process %s' % self._popen.pid
assert self.result.exit_status is not None, e_msg assert self.result.exit_status is not None, e_msg
return self.result return self.result
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册