def monitorFiles(outfiles, seconds, timeoutms):
 devnull = open('/dev/null', 'w')
 (tails, fdToFile, fdToHost) = ({}, {}, {})
 for (h, outfile) in outfiles.iteritems():
  tail = Popen(['tail', '-f', outfile], stdout=PIPE, stderr=devnull)
  fd = tail.stdout.fileno()
  tails[h] = tail
  fdToFile[fd] = tail.stdout
  fdToHost[fd] = h
 readable = poll()
 for t in tails.values():
  readable.register(t.stdout.fileno(), POLLIN)
 endTime = (time() + seconds)
 while (time() < endTime):
  fdlist = readable.poll(timeoutms)
  if fdlist:
   for (fd, _flags) in fdlist:
    f = fdToFile[fd]
    host = fdToHost[fd]
    line = f.readline().strip()
    (yield (host, line))
  else:
   (yield (None, ''))
 for t in tails.values():
  t.terminate()
 devnull.close()

def monitorFiles ( outfiles , seconds , timeoutms ) : devnull = open ( '/dev/null' , 'w' ) ( tails , fdToFile , fdToHost ) = ( { } , { } , { } ) for ( h , outfile ) in outfiles . iteritems ( ) : tail = Popen ( [ 'tail' , '-f' , outfile ] , stdout = PIPE , stderr = devnull ) fd = tail . stdout . fileno ( ) tails [ h ] = tail fdToFile [ fd ] = tail . stdout fdToHost [ fd ] = h readable = poll ( ) for t in tails . values ( ) : readable . register ( t . stdout . fileno ( ) , POLLIN ) endTime = ( time ( ) + seconds ) while ( time ( ) < endTime ) : fdlist = readable . poll ( timeoutms ) if fdlist : for ( fd , _flags ) in fdlist : f = fdToFile [ fd ] host = fdToHost [ fd ] line = f . readline ( ) . strip ( ) ( yield ( host , line ) ) else : ( yield ( None , '' ) ) for t in tails . values ( ) : t . terminate ( ) devnull . close ( )
monitor set of files and return [ .