File tree 1 file changed +13
-7
lines changed
1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change 18
18
19
19
def retry (seconds = RETRY_TIMEOUT_SECONDS ):
20
20
"""
21
- Retry a block of code until a time limit or ``break`` .
21
+ Retry a function until a condition meets or the specified time passes .
22
22
23
23
Parameters
24
24
----------
25
25
seconds : int
26
- Seconds to retry, defaults to ``RETRY_TIMEOUT_SECONDS ``, which is
27
- configurable via environmental variables.
26
+ Seconds to retry, defaults to ``8 ``, which is configurable via
27
+ ``RETRY_TIMEOUT_SECONDS`` environmental variables.
28
28
29
29
Returns
30
30
-------
@@ -34,13 +34,19 @@ def retry(seconds=RETRY_TIMEOUT_SECONDS):
34
34
Examples
35
35
--------
36
36
37
- >>> while retry ():
37
+ >>> def f ():
38
38
... p = w.attached_pane
39
39
... p.server._update_panes()
40
- ... if p.current_path == pane_path:
41
- ... break
40
+ ... return p.current_path == pane_path
41
+ ...
42
+ ... retry(f)
42
43
"""
43
- return (lambda : time .time () < time .time () + seconds )()
44
+ ini = time .time ()
45
+
46
+ while not fun ():
47
+ end = time .time ()
48
+ if end - ini >= secs :
49
+ raise Exception ('Function timed out without meeting condition' )
44
50
45
51
46
52
def get_test_session_name (server , prefix = TEST_SESSION_PREFIX ):
You can’t perform that action at this time.
0 commit comments