@@ -248,29 +248,44 @@ Gevent
248
248
~~~~~~
249
249
250
250
`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.
253
255
254
256
Instances of class ``socketio.Server `` will automatically use gevent for
255
257
asynchronous operations if the library is installed and eventlet is not
256
258
installed. To request gevent to be selected explicitly, the ``async_mode ``
257
259
option can be given in the constructor::
258
260
259
- eio = socketio.Server(async_mode='gevent')
261
+ sio = socketio.Server(async_mode='gevent')
260
262
261
263
A server configured for gevent is deployed as a regular WSGI application,
262
264
using the provided ``socketio.Middleware ``::
263
265
264
- app = socketio.Middleware(eio )
266
+ app = socketio.Middleware(sio )
265
267
from gevent import pywsgi
266
268
pywsgi.WSGIServer(('', 8000), app).serve_forever()
267
269
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
269
280
`gunicorn <gunicorn.org >`_, a fully featured pure Python web server. The
270
281
command to launch the application under gunicorn is shown below::
271
282
272
283
$ gunicorn -k gevent -w 1 module:app
273
284
285
+ Or to include WebSocket::
286
+
287
+ $ gunicorn -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 module: app
288
+
274
289
Same as with eventlet, due to limitations in its load balancing algorithm,
275
290
gunicorn can only be used with one worker process, so the ``-w 1 `` option is
276
291
required. 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
316
331
up to two outstanding requests at any given time. The Werkzeug server is
317
332
single-threaded by default, so the ``threaded=True `` option is required.
318
333
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
+
319
337
Multi-process deployments
320
338
~~~~~~~~~~~~~~~~~~~~~~~~~
321
339
0 commit comments