Last active
January 3, 2020 00:45
-
-
Save compwron/5544ba721fc9a6ad1ff4aaf3198462c4 to your computer and use it in GitHub Desktop.
demo of waiting for a condition
This file contains 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 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