5 ms·
Introducing Flask-Sockets
- rubycowgames 13y agoI'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?
- sshThis 13y agoA few questions, does this work with Python 3.3? Also, how is it better than Tornado web sockets?
- huxley 13y agoUnfortunately 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
- wbond 13y agoPython 3 compatibility was my first question also. Unfortunately this relies on gevent and gevent does not work on py3.
- kenneth_reitz 13y agoWhy does something have to be better to be useful?
- codysoyland 13y agoThis looks like a thin wrapper over gevent-websocket. The code is slightly longer than the README: https://github.com/kennethreitz/flask-sockets/blob/master/flask_sockets.py https://github.com/kennethreitz/flask-sockets/blob/master/fl... 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 13y agoWhen 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 13y agoWebsockets in python is easy. http://www.tornadoweb.org/en/stable/websocket.html http://www.tornadoweb.org/en/stable/websocket.html
- m0th87 13y agoOn 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 13y agoTornado 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 13y agoYep, totally get it. Just want to make sure people know about tornado as an option for greenfield projects.
- PhasmaFelis 13y agoI was kind of hoping this would be some sort of power socket shaped like a pocket flask.
- toanant 13y agoFlask 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.
- stevenwei 13y agoThanks 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 13y ago> (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 13y agoI 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.)