title: How can I block on readline() in python so I don't have to poll?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1475950/tail-f-in-python-with-no-time-sleep">tail -f in python with no time.sleep</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to monitor a log file that is being written to (like tail -f), and I can't figure out how to make readline() block once it reaches eof.  All of my googling has only turned up solutions to make things NON-blocking.  Does anyone know a way to make a call like this block, so I DON'T have to poll?  (I'm perfectly capable of polling and sleeping already, so if you suggest that I'm going to rate you down.)</p>
  
  <pre><code>fh = open('logfile')
  # I only want new output, so seek to the end of the file
  fh.seek(-1,2)
  while True:
     # I want this to block until the file has new output, 
     # but it sees eof and returns '' immediately
     line = fh.readline()
     # ... process the line
  </code></pre>