Skip to content

Instantly share code, notes, and snippets.

@diminoten
Last active August 29, 2015 14:05
Show Gist options
  • Save diminoten/c243bc659b43983b7250 to your computer and use it in GitHub Desktop.
Save diminoten/c243bc659b43983b7250 to your computer and use it in GitHub Desktop.
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