如何在浏览器上使用python尾随-f日志文件[复制]

问题描述 投票:-1回答:1

我想用python flask或bottle模块创建一个脚本,用/var/log/messages命令打印我的tail -f日志。

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)

当我尝试与tail -f页面只是挂起并加载永远。

python flask subprocess bottle
1个回答
1
投票

tail -f\ actually block current thread, it neverreturn`直到你终止它。

https://github.com/seb-m/pyinotifyhttp://pythonhosted.org/watchdog/将是一个更好的主意。

© www.soinside.com 2019 - 2024. All rights reserved.