multithreading - python flask alert on html while running a thread -
i using flask end of web page navigator, , can run thread on post method. thread counting class function in python file(counter.py), i'm looking way alert user front end when thread has done counting 5. there tool or library need use this? i'm not @ web programming tips help. thanks! :)
class count(threading.thread) def __init__(self): count = 0 def run(self): while count < 20: print count time.sleep(1) count += 1 if count % 5 == 0: #alert user pass
here code flask
import flask, flask.views import counter mythread = counter.count() app = flask.flask(__name__) class view(flask.views.methodview): def get(self): return flask.render_template('index.html', message=l.message) def post(self): mythread.start() return flask.redirect(flask.url_for('main')) app.add_url_rule('/', view_func=view.as_view('main'), methods=['get', 'post']) app.debug = true app.run()
and index.html. button, i'll add more pages in future
<body> <form action="/" method="post"> <input type="submit" name="submit" value="execute" /> </form> </body>
Comments
Post a Comment