def try_for(fn, timeout=5.0, delay=0.1):
 until = (time.time() + timeout)
 v = fn()
 while ((not v) and (time.time() < until)):
  time.sleep(delay)
  v = fn()
 return v

def try_for ( fn , timeout = 5.0 , delay = 0.1 ) : until = ( time . time ( ) + timeout ) v = fn ( ) while ( ( not v ) and ( time . time ( ) < until ) ) : time . sleep ( delay ) v = fn ( ) return v
calls fn every delay seconds until it returns true or timeout seconds elapse .