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

Side by Side 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: Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """A utility to run functions with timeouts and retries.""" 5 """A utility to run functions with timeouts and retries."""
6 # pylint: disable=W0702 6 # pylint: disable=W0702
7 7
8 import threading 8 import threading
9 9
10 from pylib.utils import reraiser_thread 10 from pylib.utils import reraiser_thread
(...skipping 24 matching lines...) Expand all
35 35
36 # The return value uses a list because Python variables are references, not 36 # The return value uses a list because Python variables are references, not
37 # values. Closures make a copy of the reference, so updating the closure's 37 # values. Closures make a copy of the reference, so updating the closure's
38 # reference wouldn't update where the original reference pointed. 38 # reference wouldn't update where the original reference pointed.
39 ret = [None] 39 ret = [None]
40 def RunOnTimeoutThread(): 40 def RunOnTimeoutThread():
41 ret[0] = func(*args, **kwargs) 41 ret[0] = func(*args, **kwargs)
42 42
43 while True: 43 while True:
44 try: 44 try:
45 name = 'TimeoutThread-for-%s' % threading.current_thread().name 45 name = 'TimeoutThread-%d-for-%s' % (retries,
jbudorick 2014/10/24 17:30:52 Good idea.
46 threading.current_thread().name)
46 thread_group = reraiser_thread.ReraiserThreadGroup( 47 thread_group = reraiser_thread.ReraiserThreadGroup(
47 [TimeoutRetryThread(RunOnTimeoutThread, name=name)]) 48 [TimeoutRetryThread(RunOnTimeoutThread, name=name)])
48 thread_group.StartAll() 49 thread_group.StartAll()
49 thread_group.JoinAll(watchdog_timer.WatchdogTimer(timeout)) 50 thread_group.JoinAll(watchdog_timer.WatchdogTimer(timeout))
50 return ret[0] 51 return ret[0]
51 except: 52 except:
52 if retries <= 0: 53 if retries <= 0:
53 raise 54 raise
54 retries -= 1 55 retries -= 1
OLDNEW
« build/android/pylib/utils/reraiser_thread.py ('K') | « build/android/pylib/utils/reraiser_thread.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698