Skip to content

Commit

Permalink
Merge pull request #1354 from clebergnu/lts_process_poll
Browse files Browse the repository at this point in the history
[LTS] avocado.utils.process: Avoid busy loop in run
  • Loading branch information
lmr committed Aug 4, 2016
2 parents 01b4b3f + b2f595c commit 6a70d24
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions avocado/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,21 +556,19 @@ def run(self, timeout=None, sig=signal.SIGTERM):
: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:
Expand Down

0 comments on commit 6a70d24

Please sign in to comment.