flask - Python: stream stdout from function to webpage -


i'm trying stream stdout of function webpage. some_function.main takes few mins complete , want show stdout screen (its using logger).

this code execute function don't on webpage, see on screen when run "python app.py" (i'm using flask)

from jinja2 import environment jinja2.loaders import filesystemloader  @app.route('/buildvm', methods=['get', 'post']) def buildvm():    if 'username' not in session:       return redirect(url_for('login'))     if request.method == "post" , 'username' in session:       parmsdic = {'key':'val'}         def inner(disc):           sys.path.append('/some/path')           import some_fuction           #for x in range(100):           x in some_fuction.main(disc, quite=true):              yield '{0}<br/>\n'.format(x)        env = environment(loader=filesystemloader('templates'))        tmpl = env.get_template('results.html')        return response(tmpl.generate(result=inner(parmsdic)))     return render_template('index.html') 

my results.html looks like:

{% block body %} <body>   {% line in result %}     {{ line }}   {% endfor %} </body> {% endblock %} 

any appreciated, thank in advance.

you need redirect stdout pipe , put output of pipe template. need know in answers of linked question.

p.s. pipe in-memory structure can used instead of files. discussed in linked question.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -