Skip to content

Commit

Permalink
factor wait code out in wait_util
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarjog committed Mar 22, 2016
1 parent 44c49c3 commit 5e6cdde
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions wait_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import time


class TimeoutException(Exception):
pass


def wait_while(condition, refresh=lambda: True):
def waitfor(timeout):
waited = 0
SLEEPTIME = 5

refresh()
if not condition():
return True

while waited < timeout and condition():
time.sleep(SLEEPTIME)
waited += SLEEPTIME
refresh()
if condition():
raise TimeoutException()

return waitfor

0 comments on commit 5e6cdde

Please sign in to comment.