WebSockets and WSGI together through Gunicorn

Can I use Gunicorn to handle WebSockets and regular WSGI presentations in a single application (Flask)?

I know how to get websockets to work with a Gevent WSGI server, and I can get a regular WSGI application that works with Gunicorn, with Gevent workers, but when I try to serve these two together from one application using Gunicorn, I get an error:

ValueError: View function does not return a response

Is it possible to serve two of the same application using guns? In the end, I plan to put all this on nginx, and I would not mind splitting the socket into another application and have two contacts if it does not require too many additional system resources. Until then, is there a way to do this this way?

EDIT:

I figured out how to do it. Key: 1) change the logging function for gevent, and 2) be sure to point to gunicorn that I am using the workers of the geventWebSocketWorker class.

I found part of this answer on this site: http://d.hatena.ne.jp/Malan/20121007

For the record, I think it's probably best to think that one server works with a tornado / twisted / autobahn (thanks to Jordan) and the other works with WSGI. But this is not what I wanted here :)

def log_request(self): log = self.server.log if log: if hasattr(log, "info"): log.info(self.format_request() + '\n') else: log.write(self.format_request() + '\n') import gevent gevent.pywsgi.WSGIHandler.log_request = log_request from geventwebsocket.handler import WebSocketHandler from gevent.pywsgi import WSGIServer sudo gunicorn -c gunicorn_config.py -k "geventwebsocket.gunicorn.workers.GeventWebSocketWorker" router:app 
+8
python flask websocket gunicorn gevent
source share
1 answer

Flask-Sockets may be useful.

+2
source share

All Articles