Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Unified Diff: build/android/pylib/utils/watchdog_timer.py

Issue 636273004: Make TimeoutRetryThread's stoppable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: do not catch CommandFailedError in _WaitFor Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/android/pylib/utils/watchdog_timer.py
diff --git a/build/android/pylib/utils/watchdog_timer.py b/build/android/pylib/utils/watchdog_timer.py
index d14dabb4dd7800eb1883fc7aae8cdc2b8f4a538f..69e58c81747aaa6115e9d397d251466c4300aa91 100644
--- a/build/android/pylib/utils/watchdog_timer.py
+++ b/build/android/pylib/utils/watchdog_timer.py
@@ -19,12 +19,29 @@ class WatchdogTimer(object):
Args:
timeout: The timeout in seconds. If timeout is None it will never timeout.
"""
- self._start_time = time.time()
self._timeout = timeout
+ self._start_time = None
jbudorick 2014/10/30 02:27:03 This should still set self._start_time to time.tim
perezju 2014/10/30 18:44:45 Yeah, I scrapped much of this in the new version.
+ self._end_time = None
+ self.Reset()
def Reset(self):
"""Resets the timeout countdown."""
self._start_time = time.time()
+ if self._timeout is None:
+ self._end_time = None
+ else:
+ self._end_time = self._start_time + self._timeout
+
+ def ElapsedTime(self):
+ """Returns the number of seconds elapsed since the last reset."""
+ return time.time() - self._start_time
+
+ def RemainingTime(self):
+ """Returns the number of seconds remaining until the watchdog times out."""
+ if self._end_time is None:
+ return None
+ else:
+ return self._end_time - time.time()
def IsTimedOut(self):
"""Whether the watchdog has timed out.
@@ -32,6 +49,7 @@ class WatchdogTimer(object):
Returns:
True if the watchdog has timed out, False otherwise.
"""
- if self._timeout is None:
+ if self._end_time is None:
return False
- return time.time() - self._start_time > self._timeout
+ else:
+ return time.time() > self._end_time
« build/android/pylib/utils/timeout_retry.py ('K') | « build/android/pylib/utils/timeout_retry.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698