human
Complete this python program:
def _poll_for_status(poll_fn, obj_id, action, final_ok_states, poll_period=5, show_progress=True, status_field='status', silent=False):
assistant
#Here is the Python code you requested.

    """Block while an action is being performed, periodically printing
    progress.
    """
    def print_progress(progress):
        if show_progress:
            msg = (_('\rServer    %(action)s...    %(progress)s%%    complete') % dict(action=action, progress=progress))
        else:
            msg = (_('\rServer    %(action)s...') % dict(action=action))
        sys.stdout.write(msg)
        sys.stdout.flush()
    if (not silent):
        print()
    while True:
        obj = poll_fn(obj_id)
        status = getattr(obj, status_field)
        if status:
            status = status.lower()
        progress = (getattr(obj, 'progress', None) or 0)
        if (status in final_ok_states):
            if (not silent):
                print_progress(100)
                print(_('\nFinished'))
            break
        elif (status == 'error'):
            if (not silent):
                print((_('\nError    %s    server') % action))
            raise exceptions.ResourceInErrorState(obj)
        elif (status == 'deleted'):
            if (not silent):
                print((_('\nDeleted    %s    server') % action))
            raise exceptions.InstanceInDeletedState(obj.fault['message'])
        if (not silent):
            print_progress(progress)
        time.sleep(poll_period)