-1

I want to create a script with python flask or bottle module to print my /var/log/messages logs with tail -f command.

import subprocess
from bottle import route, response, run

@route("/")
def file():
    response.content_type = "text/plain"
    while True:
        return subprocess.check_output(["tail", "-4", "file"])

run(host='localhost', port=888)

when i try it with tail -f the page just hangs and loads for ever.

2
  • tail -f actually blocks current process. When you type it on terminal, it also blocks you, right? Commented Mar 1, 2018 at 8:58
  • the script run fine but on localhost:888/ the page loads forever with no output. Commented Mar 1, 2018 at 9:09

1 Answer 1

1

tail -f\ actually block current thread, it neverreturn` until you terminate it.

https://github.com/seb-m/pyinotify or http://pythonhosted.org/watchdog/ Would be a better idea.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.