@@ -248,29 +248,44 @@ Gevent
248248~~~~~~
249249
250250`Gevent <http://gevent.org >`_ is another asynchronous framework based on
251- coroutines, very similar to eventlet. Only the long-polling transport is
252- currently available when using gevent.
251+ coroutines, very similar to eventlet. An Socket.IO server deployed with
252+ gevent has access to the long-polling transport. If project
253+ `gevent-websocket <https://bitbucket.org/Jeffrey/gevent-websocket/ >`_ is
254+ installed, the WebSocket transport is also available.
253255
254256Instances of class ``socketio.Server `` will automatically use gevent for
255257asynchronous operations if the library is installed and eventlet is not
256258installed. To request gevent to be selected explicitly, the ``async_mode ``
257259option can be given in the constructor::
258260
259- eio = socketio.Server(async_mode='gevent')
261+ sio = socketio.Server(async_mode='gevent')
260262
261263A server configured for gevent is deployed as a regular WSGI application,
262264using the provided ``socketio.Middleware ``::
263265
264- app = socketio.Middleware(eio )
266+ app = socketio.Middleware(sio )
265267 from gevent import pywsgi
266268 pywsgi.WSGIServer(('', 8000), app).serve_forever()
267269
268- An alternative to running the eventlet WSGI server as above is to use
270+ If the WebSocket transport is installed, then the server must be started as
271+ follows::
272+
273+ from gevent import pywsgi
274+ from geventwebsocket.handler import WebSocketHandler
275+ app = socketio.Middleware(sio)
276+ pywsgi.WSGIServer(('', 8000), app,
277+ handler_class=WebSocketHandler).serve_forever()
278+
279+ An alternative to running the gevent WSGI server as above is to use
269280`gunicorn <gunicorn.org >`_, a fully featured pure Python web server. The
270281command to launch the application under gunicorn is shown below::
271282
272283 $ gunicorn -k gevent -w 1 module:app
273284
285+ Or to include WebSocket::
286+
287+ $ gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 module: app
288+
274289Same as with eventlet, due to limitations in its load balancing algorithm,
275290gunicorn can only be used with one worker process, so the ``-w 1 `` option is
276291required. Note that a single eventlet worker can handle a large number of
@@ -316,6 +331,9 @@ can handle multiple concurrent requests using threads, since a client can have
316331up to two outstanding requests at any given time. The Werkzeug server is
317332single-threaded by default, so the ``threaded=True `` option is required.
318333
334+ Note that servers that use worker processes instead of threads, such as
335+ gunicorn, do not support a Socket.IO server configured in threading mode.
336+
319337Multi-process deployments
320338~~~~~~~~~~~~~~~~~~~~~~~~~
321339
0 commit comments