我想用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)
进行尝试时,页面会挂起并永远加载。
答案 0 :(得分:1)
tail -f\ actually block current thread, it never
返回`直到你终止它。
https://github.com/seb-m/pyinotify或http://pythonhosted.org/watchdog/会更好。