Skip to content

Instantly share code, notes, and snippets.

@compwron compwron/wait_for_demo.py
Last active Jan 3, 2020

Embed
What would you like to do?
demo of waiting for a condition
import time
from random import randint
def demo():
foo = randint(0, 100)
print(f"int is {foo}")
return foo % 5 == 0
def _wait_for(condition_func, interval=0.5, max_time=15):
started_at = time.time()
while time.time() < started_at + max_time:
done = condition_func()
if done:
print('we made it')
return
else:
print('not yet')
time.sleep(interval)
print('It took too long so we stopped')
_wait_for(demo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.