Skip to content

Instantly share code, notes, and snippets.

@compwron
Last active January 3, 2020 00:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save compwron/5544ba721fc9a6ad1ff4aaf3198462c4 to your computer and use it in GitHub Desktop.
Save compwron/5544ba721fc9a6ad1ff4aaf3198462c4 to your computer and use it in GitHub Desktop.
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