From d05cf6fa8fe843395066c4d9f0f3c0cf7be41674 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 22 Nov 2010 22:21:04 +0100
Subject: [PATCH] utils._RunCmdPipe: simplify the timeout logic
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

There are two issues: first, it's simpler to assign directly to pt
instead of via another local variable. Second, this code doesn't make
sense:
  if lt < 0:
    break
  pt = max(0, lt)

If lt is indeed < 0, then the code will break. Otherwise, lt β‰₯ 0, and
max(0, lt) will always be equal to lt. So we remove the extra
assignment.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: RenΓ© Nussbaumer <rn@google.com>
---
 lib/utils.py | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/lib/utils.py b/lib/utils.py
index 9535d5355..d2020f967 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -567,21 +567,17 @@ def _RunCmdPipe(cmd, env, via_shell, cwd, interactive, timeout,
 
     while fdmap:
       if poll_timeout:
-        current_timeout = poll_timeout() * 1000
-        if current_timeout < 0:
+        pt = poll_timeout() * 1000
+        if pt < 0:
           if linger_timeout is None:
             logging.warning(msg_timeout)
             if child.poll() is None:
               timeout_action = _TIMEOUT_TERM
               IgnoreProcessNotFound(os.kill, child.pid, signal.SIGTERM)
             linger_timeout = RunningTimeout(_linger_timeout, True).Remaining
-          lt = linger_timeout() * 1000
-          if lt < 0:
+          pt = linger_timeout() * 1000
+          if pt < 0:
             break
-
-          pt = max(0, lt)
-        else:
-          pt = current_timeout
       else:
         pt = None
 
-- 
GitLab