avocado.utils.process: Make sure timeout propagated

Currently when the process time-outs, it's killed by default with
SIGTERM and then the status is reported. This usually results in process
returning non-zero status, which is then reported to the user. The
problem is that SIGTERM can be caught and handled inside the executed
command and it can report 0. Then the user does not know whether the
command actually finished on time or whether it was killed by avocado.

This commit sets the `self.result.interrupted`, which makes sure the
status is propagated even when the process finishes with zero.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 164551c2
......@@ -563,12 +563,16 @@ class SubProcess(object):
:returns: The command result object.
:rtype: A :class:`CmdResult` instance.
"""
def timeout_handler():
self.send_signal(sig)
self.result.interrupted = "timeout after %ss" % timeout
self._init_subprocess()
if timeout is None:
self.wait()
elif timeout > 0.0:
timer = threading.Timer(timeout, self.send_signal, [sig])
timer = threading.Timer(timeout, timeout_handler)
try:
timer.start()
self.wait()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册