import time


def expBackoff(action, condition, max_attempts=10):
  """
  Calls action() up to max_attempts times until condition() becomes true, with exponential backoff. Returns a bool flag indicating whether action() succeded.
  """
  timeout = 1

  for attempt in range(max_attempts):
    action()

    if condition():
      return True

    print("### Condition not met, retrying in {0} seconds...".format(timeout))
    time.sleep(timeout)
    timeout *= 2

  return False