def poll_with_timeout(timeout_s, break_func, wake_every_s=60):
    """
    Calls :attr:`break_func` every :attr:`wake_every_s` seconds for a total
    duration of :attr:`timeout_s` seconds, or until :attr:`break_func` returns
    something other than ``None``.

    If :attr:`break_func` returns anything other than ``None``, that value is
    returned immediately.

    Otherwise, continues polling until the timeout is reached, then returns
    ``None``.

    """
    time_slept = 0
    if wake_every_s > 60:
        msg = '... sleeping for %0.2f minutes' % (wake_every_s / 60.0)
    else:
        msg = '... sleeping for %d seconds' % wake_every_s
    res = break_func()
    while res is None and time_slept < timeout_s:
        log.debug(msg)
        time.sleep(wake_every_s)
        time_slept += wake_every_s
        res = break_func()
    return res
def poll_with_timeout ( timeout_s , break_func , wake_every_s = 60 ) : time_slept = 0 if wake_every_s > 60 : msg = '... sleeping for %0.2f minutes' % ( wake_every_s / 60.0 ) else : msg = '... sleeping for %d seconds' % wake_every_s res = break_func ( ) while res is None and time_slept < timeout_s : log . debug ( msg ) time . sleep ( wake_every_s ) time_slept += wake_every_s res = break_func ( ) return res
Calls :attr:`break_func` every :attr:`wake_every_s` seconds for a total
    duration of :attr:`timeout_s` seconds, or until :attr:`break_func` returns
    something other than ``None``.

    If :attr:`break_func` returns anything other than ``None``, that value is
    returned immediately.

    Otherwise, continues polling until the timeout is reached, then returns
    ``None``.