def poll_for(filename, needles, timeout=5):
 if isinstance(needles, str):
  needles = [needles]
 start = time()
 needle = content = None
 while ((time() - start) < timeout):
  with open(filename) as f:
   content = f.read()
  for needle in needles:
   if (needle in content):
    return True
  sleep(0.1)
 raise TimeoutException(('Timeout polling "%s" for "%s". Content: %s' % (filename, needle, content)))

def poll_for ( filename , needles , timeout = 5 ) : if isinstance ( needles , str ) : needles = [ needles ] start = time ( ) needle = content = None while ( ( time ( ) - start ) < timeout ) : with open ( filename ) as f : content = f . read ( ) for needle in needles : if ( needle in content ) : return True sleep ( 0.1 ) raise TimeoutException ( ( 'Timeout polling "%s" for "%s". Content: %s' % ( filename , needle , content ) ) )
poll a file for a given string .