Skip to content

Instantly share code, notes, and snippets.

@TallGirlVanessa
Created October 6, 2014 22:27
Show Gist options
  • Save TallGirlVanessa/03e3b0f1218e699c38f3 to your computer and use it in GitHub Desktop.
Save TallGirlVanessa/03e3b0f1218e699c38f3 to your computer and use it in GitHub Desktop.
Send result of backend process to web socket
#!/usr/bin/env python
from flask import Flask, render_template
from flask.ext.uwsgi_websocket import WebSocket
app = Flask(__name__)
ws = WebSocket(app)
@app.route('/')
def index():
return render_template('index.html')
@ws.route('/websocket')
def echo(ws):
backend_fd = start_preparing_file()
timeout = 3
while True:
uwsgi.wait_fd_read(backend_fd, timeout)
uwsgi.suspend()
ready_fd = uwsgi.ready_fd()
if fd > -1:
# Insert verification that the backend process worked here
ws.send('download_ready')
return
else:
ws.recv_nb() # Keep-alive
if __name__ == '__main__':
app.run(debug=True, threads=16)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment