File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change 1818
1919def retry (seconds = RETRY_TIMEOUT_SECONDS ):
2020 """
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 .
2222
2323 Parameters
2424 ----------
2525 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.
2828
2929 Returns
3030 -------
@@ -34,13 +34,19 @@ def retry(seconds=RETRY_TIMEOUT_SECONDS):
3434 Examples
3535 --------
3636
37- >>> while retry ():
37+ >>> def f ():
3838 ... p = w.attached_pane
3939 ... p.server._update_panes()
40- ... if p.current_path == pane_path:
41- ... break
40+ ... return p.current_path == pane_path
41+ ...
42+ ... retry(f)
4243 """
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' )
4450
4551
4652def get_test_session_name (server , prefix = TEST_SESSION_PREFIX ):
You can’t perform that action at this time.
0 commit comments