How to integrate flask and flask_sockets into a single app running under uwsgi

2k views Asked by At

I have an existing app running uwsgi/flask behind nginx. I want to integrate websockets into the same app. Flask sockets looks promising, so I'm trying that.

Flask sockets briefly mentions running gevent-websocket, but no sample code is provided to integrate an existing app into this setup. I've also tried several combinations of gevent-websocket with my existing flask app, but I still keep getting 500s. Additionally, it would be nice if I could find out the nature of the 500s, but the errors don't show up in the uwsgi log, as they do for the existing flask app. So, if you have any debugging dips to show a tracedump, that'd be great.

Can anyone help me get a simple echo route working with this setup? Thanks in advance.

FYI, I'm currently using:

  • uWSGI 1.0.3-debian
  • python 2.7.3
  • Flask 0.10.1
  • nginx 1.4.3
  • Flask Sockets 0.1
2

There are 2 answers

3
roberto On BEST ANSWER

If you upgrade to uWSGI 2.0 you get websockets support for free without the need of additional frameworks and with gevent compatibility. More important you get a really fast implementation (suitable for gaming):

http://uwsgi-docs.readthedocs.org/en/latest/WebSockets.html

0
Homer6 On

Although @roberto's solution is likely viable, it's a little too soon from the last major release for me to push it out to production.

I just went back to using socket.io and node in the interim. As time passes, maybe his suggestion will be more viable for me.