avocado.utils.process: Avoid busy loop in run

This patch uses Timer instead of a busy poll loop when using
`process.run` with timeout.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 a4104d6c
......@@ -563,21 +563,19 @@ class SubProcess(object):
:rtype: A :class:`CmdResult` instance.
"""
self._init_subprocess()
start_time = time.time()
if timeout is None:
self.wait()
if timeout > 0.0:
while time.time() - start_time < timeout:
self.poll()
if self.result.exit_status is not None:
break
elif timeout > 0.0:
timer = threading.Timer(timeout, self.send_signal, [sig])
try:
timer.start()
self.wait()
finally:
timer.cancel()
if self.result.exit_status is None:
internal_timeout = 1.0
self.send_signal(sig)
stop_time = time.time() + internal_timeout
stop_time = time.time() + 1
while time.time() < stop_time:
self.poll()
if self.result.exit_status is not None:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册