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

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

Issue 13590002: [Android] Print the stack of deadlocked threads when sharding. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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.py
diff --git a/build/android/pylib/utils/watchdog.py b/build/android/pylib/utils/watchdog.py
new file mode 100644
index 0000000000000000000000000000000000000000..84f1cc5ee405d92ed3a6c4274a964e2a379210bd
--- /dev/null
+++ b/build/android/pylib/utils/watchdog.py
@@ -0,0 +1,47 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Watchdog timeout objects."""
+
+import time
+
+
+class Watchdog(object):
+ """A resetable timeout-based watchdog.
+
+ This object is threadsafe.
+ """
+
+ def __init__(self, timeout):
+ """Initializes the watchdog.
+
+ Args:
+ timeout: The timeout in seconds.
+ """
+ self._start_time = time.time()
+ self._timeout = timeout
+
+ def Reset(self):
+ """Resets the timeout countdown."""
+ self._start_time = time.time()
+
+ def IsTimedOut(self):
+ """Whether the watchdog has timed out.
+
+ Returns:
+ True if the watchdog has timed out, False otherwise.
+ """
+ return time.time() - self._start_time > self._timeout
+
+
+class MockWatchdog(Watchdog):
+ """A watchdog which never times out."""
+
+ #override
+ def __init__(self, timeout=0):
+ super(MockWatchdog, self).__init__(timeout)
+
+ #override
+ def IsTimedOut(self):
+ return False

Powered by Google App Engine
This is Rietveld 408576698