Popular recipes by Jason Morriss http://code.activestate.com/recipes/users/4174039/2011-05-20T16:32:59-07:00ActiveState Code RecipesTail a continuously growing file (like tail -f filename) (Python) 2011-05-20T16:32:59-07:00Jason Morrisshttp://code.activestate.com/recipes/users/4174039/http://code.activestate.com/recipes/577710-tail-a-continuously-growing-file-like-tail-f-filen/ <p style="color: grey"> Python recipe 577710 by <a href="/recipes/users/4174039/">Jason Morriss</a> (<a href="/recipes/tags/file/">file</a>, <a href="/recipes/tags/rotate/">rotate</a>, <a href="/recipes/tags/tail/">tail</a>). </p> <p>This is my version of a "File Tail" class for Python3 (will not work on Python2 w/o a couple of modifications). My original inspiration came from the perl File::Tail module.</p> <p>Transparently handles files that get rotated or truncated. </p> <ul> <li>Does not take 100% CPU. </li> <li>Does not take up much memory.</li> <li>Is capable of handling any size log file.</li> <li><em>Not tested on Windows</em></li> </ul> <p>Example:</p> <pre class="prettyprint"><code>from filetail import FileTail tail = FileTail("/var/log/syslog") for line in tail: print(line, end="") </code></pre>