def poll_until_completed()

in ml-tools-python/wait_for_entity.py [0:0]


def poll_until_completed(entity_id, entity_type_str):
    ml = boto.connect_machinelearning()
    polling_function = {
        'ds': ml.get_data_source,
        'ml': ml.get_ml_model,
        'ev': ml.get_evaluation,
        'bp': ml.get_batch_prediction,
    }[entity_type_str]
    delay = 2
    while True:
        results = polling_function(entity_id)
        status = results['Status']
        message = results.get('Message', '')
        now = str(datetime.datetime.now().time())
        print("Object %s is %s (%s) at %s" % (entity_id, status, message, now))
        if status in ['COMPLETED', 'FAILED', 'INVALID']:
            break

        # exponential backoff with jitter
        delay *= random.uniform(1.1, 2.0)
        time.sleep(delay)
    print(json.dumps(results, indent=2))