

Introducing Flask-Sockets - jnoller
http://kennethreitz.org/introducing-flask-sockets/

======
stevenwei
Thanks for this. A few months ago I looked into getting gevent-socketio up and
running to do real-time messaging between a Flask app and an iOS app. gevent-
socketio provides event handling and a messaging protocol on top of websockets
that I thought would be useful.

However, based on my testing, in its current state it's nowhere near ready for
production. There are some serious bugs relating to memory leaks, improperly
closing stale sockets, and deployment on Gunicorn with # workers > 1 is not
currently possible. (And in practice I don't think you would want to deploy on
anything besides Gunicorn.) The project also seems to be somewhat inactive,
there are a lot of open critical issues and there hasn't been any real
activity in the last 6 months or so.

At this point I am considering removing the library and using a straight
websocket implementation with a simpler protocol instead.

~~~
tyrion
> (And in practice I don't think you would want to deploy on anything besides
> Gunicorn.)

(You should definitely have a look at uWSGI.)

~~~
stevenwei
I have been running uWSGI for many years, I only recently made the switch to
Gunicorn for the async gevent/websockets support.

(The last time I looked, which was a few months ago anyway, uWSGI support for
gevent/websockets wasn't very robust.)

------
codysoyland
This looks like a thin wrapper over gevent-websocket. The code is slightly
longer than the README: [https://github.com/kennethreitz/flask-
sockets/blob/master/fl...](https://github.com/kennethreitz/flask-
sockets/blob/master/flask_sockets.py)

Not to discredit the attempt to make gevent-websocket more accessible, but
there's nothing really new here. Here's an example of using gevent-websocket
with flask without this library:
[https://gist.github.com/lrvick/1185629](https://gist.github.com/lrvick/1185629)

~~~
kenneth_reitz
When used in conjunction with Gunicorn, this setup gets significantly more
complicated, involving middlewares and monkeypatches. That's why I wrote the
module :)

This also doesn't _require_ the use of Gevent, like using gevent-websockets
directly does. Anything that inserts `wsgi.websocket` into the WSGI environ
will suffice here.

------
twism
Websockets in python is easy.

[http://www.tornadoweb.org/en/stable/websocket.html](http://www.tornadoweb.org/en/stable/websocket.html)

~~~
m0th87
On top of that, tornado has built-in support for multiprocessing, so you can
forego gunicorn as well:
[https://gist.github.com/jholster/2290574](https://gist.github.com/jholster/2290574)

~~~
kenneth_reitz
Tornado is an excellent choice for websockets, but someone shouldn't have to
switch web frameworks just to support them. This works well for people who
like working with Flask and have existing applications that they want to add
websocket support to.

~~~
m0th87
Yep, totally get it. Just want to make sure people know about tornado as an
option for greenfield projects.

------
toanant
Flask users will be grateful for support of web-sockets, because beginner in
python can use flask & now flask-sockets too for building small but useful
projects. Thanks Reitz for this.

------
rubycowgames
I've been using gevent-socketio for websockets with Flask. I'm new to python.
Can someone tell me why I'd want to use this over gevent-socketio?

~~~
Rauchg
Maybe if you _only_ want WebSocket, and you're already using Flask, and you
want to give up events and roll out your messaging protocol. Sounds like a lot
of work.

------
sshThis
A few questions, does this work with Python 3.3?

Also, how is it better than Tornado web sockets?

~~~
huxley
Unfortunately it looks like Gevent still has issues with Python 3:

[https://github.com/surfly/gevent/issues/38](https://github.com/surfly/gevent/issues/38)

You can check Python 3 support for major packages at:
[https://python3wos.appspot.com](https://python3wos.appspot.com)

------
PhasmaFelis
I was kind of hoping this would be some sort of power socket shaped like a
pocket flask.

