poll

Utilities for polling, retrying, and exception handling.

poll.poll(until, timeout=15, interval=1)

Decorator for functions that should be retried until a condition or a timeout.

Parameters:
  • until – Called with the return value of the function; return True if the operation was successful (and retrying should stop)
  • timeout (float) – How long to keep retrying the operation in seconds
  • interval (float) – How long to sleep in between attempts in seconds
>>> class TestPoll:
...     def __init__(self):
...         self.x = 0
...     @poll(lambda x: x == 3, interval=0.01)
...     def test(self):
...         print(self.x)
...         self.x += 1
...         return self.x
>>> TestPoll().test()
0
1
2
3

Indices and tables