How can I tail a log file in Python?

Non Blocking If you are on linux (as windows does not support calling select on files) you can use the subprocess module along with the select module. import time import subprocess import select f = subprocess.Popen([‘tail’,’-F’,filename],\ stdout=subprocess.PIPE,stderr=subprocess.PIPE) p = select.poll() p.register(f.stdout) while True: if p.poll(1): print f.stdout.readline() time.sleep(1) This polls the output pipe for new … Read more