如何在浏览器上使用python tail -f日志文件

时间:2018-03-01 08:43:33

标签: python flask subprocess bottle

我想用python flask或bottle模块创建一个脚本,用// Trying to concatenate two string as [] coerce to strings = 24 [2] + [4] // Converting 2 and 4 to number and then adding = 6 (+[2]) + (+[4]) // Converting 2 to number and 4,5 will be coerced to string = 24,5 +[2] + [4,5] 命令打印我的/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) 进行尝试时,页面会挂起并永远加载。

1 个答案:

答案 0 :(得分:1)

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

https://github.com/seb-m/pyinotifyhttp://pythonhosted.org/watchdog/会更好。