locking: Convert pipe condition to new timeout class
authorMichael Hanselmann <hansmi@google.com>
Thu, 15 Oct 2009 12:38:31 +0000 (14:38 +0200)
committerMichael Hanselmann <hansmi@google.com>
Thu, 15 Oct 2009 14:47:32 +0000 (16:47 +0200)
Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/locking.py

index 0a467a7..37b2a8b 100644 (file)
@@ -134,10 +134,14 @@ class _SingleNotifyPipeConditionWaiter(object):
     @param timeout: Timeout for waiting (can be None)
 
     """
-    start_time = time.time()
-    remaining_time = timeout
+    running_timeout = RunningTimeout(timeout, True)
+
+    while True:
+      remaining_time = running_timeout.Remaining()
+
+      if remaining_time is not None and remaining_time < 0.0:
+        break
 
-    while timeout is None or remaining_time > 0:
       try:
         result = self._poller.poll(remaining_time)
       except EnvironmentError, err:
@@ -149,10 +153,6 @@ class _SingleNotifyPipeConditionWaiter(object):
       if result and result[0][0] == self._fd:
         break
 
-      # Re-calculate timeout if necessary
-      if timeout is not None:
-        remaining_time = start_time + timeout - time.time()
-
 
 class _BaseCondition(object):
   """Base class containing common code for conditions.