Skip to content

Instantly share code, notes, and snippets.

@isaaguilar
Created December 15, 2016 21:01
Show Gist options
  • Save isaaguilar/89bf5c881209a66698c69a7197befd2a to your computer and use it in GitHub Desktop.
Save isaaguilar/89bf5c881209a66698c69a7197befd2a to your computer and use it in GitHub Desktop.
tail -f for python
import subprocess, re
def tail_and_quit(filename, regex_to_match):
try:
f = subprocess.Popen(['tail', '-F', filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
line = f.stdout.readline()
match = re.search(regex_to_match, line)
if match: break
finally: f.kill()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment