Utility method to try out the callback method at most no_of_times with a interval of retry_interval, Will return immediately if callback returns True. The callback method should be written to return a list of values first being a boolean
(retry_interval=2, no_of_times=2, callback=None, *callback_args)
| 598 | |
| 599 | |
| 600 | def wait_until(retry_interval=2, no_of_times=2, callback=None, *callback_args): |
| 601 | """ Utility method to try out the callback method at most no_of_times with a interval of retry_interval, |
| 602 | Will return immediately if callback returns True. The callback method should be written to return a list of values first being a boolean """ |
| 603 | |
| 604 | if callback is None: |
| 605 | raise ("Bad value for callback method !") |
| 606 | |
| 607 | wait_result = False |
| 608 | for i in range(0,no_of_times): |
| 609 | time.sleep(retry_interval) |
| 610 | wait_result, return_val = callback(*callback_args) |
| 611 | if not(isinstance(wait_result, bool)): |
| 612 | raise ("Bad parameter returned from callback !") |
| 613 | if wait_result : |
| 614 | break |
| 615 | |
| 616 | return wait_result, return_val |