【发布时间】:2018-03-01 22:20:19
【问题描述】:
我想使用 python flask 或 bottle 模块创建一个脚本,以使用 tail -f 命令打印我的 /var/log/messages 日志。
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 时,页面会永远挂起并加载。
【问题讨论】:
-
tail -f实际上阻塞了当前进程。当你在终端上输入它时,它也会阻止你,对吧? -
脚本运行良好,但在 localhost:888/ 页面永远加载,没有输出。
标签: python flask subprocess bottle