Changes between Initial Version and Version 1 of Ticket #32831, comment 6


Ignore:
Timestamp:
Jun 10, 2021, 7:37:34 AM (4 years ago)
Author:
Chris Jerdonek

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #32831, comment 6

    initial v1  
    1 A possible pattern for fixing issues like this would be to keep retrying the assertion in a `while` loop, with a small sleep in between each attempt, and a relatively large cumulative amount of time before giving up. That would make it as pass as quickly as possible, without waiting longer than necessary.
     1A possible pattern for fixing issues like this would be to keep retrying the assertion in a `while` loop, with a small sleep in between each attempt, and a relatively large cumulative amount of time before giving up. That would make it as pass as quickly as possible, without waiting longer than necessary. I'm thinking something like--
     2
     3{{{#!python
     4    def assert_with_retries(self, assert_func, interval_time, total_time, *args, **kwargs):
     5        start = time.time()
     6        while True:
     7            try:
     8                assert_func(*args, **kwargs)
     9            except Exception as exc:
     10                if time.time() - start > total_time:
     11                    raise RuntimeError(f'Total retry time exceeded.') from exc
     12            else:
     13                break
     14            time.sleep(interval_time)
     15}}}
Back to Top