我有一个场景,我想通过flaskapi显示长时间运行脚本的输出。我引用了一个关于烧瓶的例子,它很管用。我在浏览器中得到dmesg
蒸汽。在
import subprocess
import time
from flask import Flask, Response
app = Flask(__name__)
@app.route('/yield')
def index():
def inner():
proc = subprocess.Popen(
['dmesg'], # call something with a lot of output so we can see it
shell=True,
stdout=subprocess.PIPE
)
for line in iter(proc.stdout.readline,''):
time.sleep(1) # Don't need this just shows the text streaming
yield line.rstrip() + '<br/>\n'
return Response(inner(), mimetype='text/html') # text/html is required for most browsers to show this
问题是,我已经使用Flask-Restful
很久了。所以我想用它来做流媒体。我试过了,但没用。在
请帮忙
目前没有回答
相关问题 更多 >
编程相关推荐