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

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

Issue 636273004: Make TimeoutRetryThread's stoppable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: some fixes, tests ready 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/timeout_retry.py
diff --git a/build/android/pylib/utils/timeout_retry.py b/build/android/pylib/utils/timeout_retry.py
index bae8b16cf7ffd5b16b32e849ffb1af26bf290ead..5cdd83b80d4fefd4a4cf38fad8e7581b6921e72e 100644
--- a/build/android/pylib/utils/timeout_retry.py
+++ b/build/android/pylib/utils/timeout_retry.py
@@ -6,13 +6,27 @@
# pylint: disable=W0702
import threading
+import time
from pylib.utils import reraiser_thread
from pylib.utils import watchdog_timer
class TimeoutRetryThread(reraiser_thread.ReraiserThread):
- pass
+ def __init__(self, *args, **kwargs):
+ super(TimeoutRetryThread, self).__init__(*args, **kwargs)
+ self._timeout_expired = False
+ self._start = time.time()
+
+ def ElapsedTime(self):
+ return time.time() - self._start
+
+ def ExpireTimeout(self):
+ self._timeout_expired = True
+
+ def CheckTimeout(self):
+ if self._timeout_expired:
+ raise reraiser_thread.TimeoutError('Thread timed out')
perezju 2014/10/27 17:43:34 Moved the changes from reraiser_thread into here.
jbudorick 2014/10/27 19:15:37 Definitely, but I'm still not a fan of making the
def Run(func, timeout, retries, args=None, kwargs=None):
@@ -40,15 +54,19 @@ def Run(func, timeout, retries, args=None, kwargs=None):
def RunOnTimeoutThread():
ret[0] = func(*args, **kwargs)
+ num_try = 1
while True:
+ child_thread = TimeoutRetryThread(
+ RunOnTimeoutThread,
+ name='TimeoutThread-%d-for-%s' % (num_try,
+ threading.current_thread().name))
perezju 2014/10/27 17:43:34 With, say, 3 retries, thread numbers now count fro
try:
- name = 'TimeoutThread-for-%s' % threading.current_thread().name
- thread_group = reraiser_thread.ReraiserThreadGroup(
- [TimeoutRetryThread(RunOnTimeoutThread, name=name)])
+ thread_group = reraiser_thread.ReraiserThreadGroup([child_thread])
thread_group.StartAll()
thread_group.JoinAll(watchdog_timer.WatchdogTimer(timeout))
return ret[0]
except:
- if retries <= 0:
+ child_thread.ExpireTimeout()
+ if num_try > retries:
raise
- retries -= 1
+ num_try += 1
« build/android/pylib/device/device_utils.py ('K') | « build/android/pylib/device/device_utils_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698