Last active
August 29, 2015 14:05
-
-
Save diminoten/c243bc659b43983b7250 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import random | |
import time | |
def wait_for_condition(action, seconds): | |
endtime = datetime.datetime.now() + datetime.timedelta(seconds=seconds) | |
condition = False | |
while endtime > datetime.datetime.now() and not condition: | |
condition = action() | |
if not condition: | |
raise Exception() | |
def do_thing(): | |
time.sleep(1) | |
return True if random.randint(0, 10) > 100 else False | |
wait_for_condition(do_thing, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment