Can I use file.readline in a blocking manner? Am I doing this right?
<p>I'm trying to write a something that monitors a log file and adds a timestamp when it sees a complete line: </p>

<pre><code>import sys

f = open(sys.argv[1])
if not f:
    print 'Failed to open %s' % sys.argv[1]

print sys.argv[1]

import time

try:
    while True:
        line = f.readline().replace('\n', '')
        if not line:
            continue
        print time.time(), line
except KeyboardInterrupt:
    pass

f.close()
</code></pre>

<p>The check for line contents is there because, to my surprise, readlines does not block, but rather returns an empty string for the end of file immediately. </p>

<p>So then, for monitoring files, I have a few questions: Is there any way I can set this to block? I'm seeing empty strings in this loop, is there any chance they don't actually represent an end of line? Do files that are still opened for writing have end of line characters added to them? </p>
