Executes a function at regular intervals while the condition is false and the amount of attempts < maxAttempts. :param condition: a function :param delay: the delay in second :param max_attempts: the maximum number of attempts. So the timeout of this fun
(condition, delay, max_attempts)
| 19 | |
| 20 | |
| 21 | def wait_until(condition, delay, max_attempts): |
| 22 | """ |
| 23 | Executes a function at regular intervals while the condition |
| 24 | is false and the amount of attempts < maxAttempts. |
| 25 | :param condition: a function |
| 26 | :param delay: the delay in second |
| 27 | :param max_attempts: the maximum number of attempts. So the timeout |
| 28 | of this function is delay*max_attempts |
| 29 | """ |
| 30 | attempt = 0 |
| 31 | while not condition() and attempt < max_attempts: |
| 32 | attempt += 1 |
| 33 | time.sleep(delay) |
| 34 | |
| 35 | if attempt >= max_attempts: |
| 36 | raise Exception("Condition is still False after {} attempts.".format(max_attempts)) |
| 37 | |
| 38 | |
| 39 | def wait_until_not_raised(condition, delay, max_attempts): |