File tree Expand file tree Collapse file tree 4 files changed +47
-12
lines changed
Expand file tree Collapse file tree 4 files changed +47
-12
lines changed Original file line number Diff line number Diff line change @@ -428,6 +428,29 @@ functions in the standard library with equivalent asynchronous versions. While
428428python-socketio does not require monkey patching, other libraries such as
429429database drivers are likely to require it.
430430
431+ Gevent with uWSGI
432+ ~~~~~~~~~~~~~~~~~
433+
434+ When using the uWSGI server in combination with gevent, the Socket.IO server
435+ can take advantage of uWSGI's native WebSocket support.
436+
437+ Instances of class ``socketio.Server `` will automatically use this option for
438+ asynchronous operations if both gevent and uWSGI are installed and eventlet is
439+ not installed. To request this asynchoronous mode explicitly, the
440+ ``async_mode `` option can be given in the constructor::
441+
442+ # gevent with uWSGI
443+ sio = socketio.Server(async_mode='gevent_uwsgi')
444+
445+ A complete explanation of the configuration and usage of the uWSGI server is
446+ beyond the scope of this documentation. The uWSGI server is a fairly complex
447+ package that provides a large and comprehensive set of options. It must be
448+ compiled with WebSocket and SSL support for the WebSocket transport to be
449+ available. As way of an introduction, the following command starts a uWSGI
450+ server for the ``latency.py `` example on port 5000::
451+
452+ $ uwsgi --http :5000 --gevent 1000 --http-websockets --master --wsgi-file latency.py --callable app
453+
431454Standard Threading Library
432455~~~~~~~~~~~~~~~~~~~~~~~~~~
433456
Original file line number Diff line number Diff line change 1- # set async_mode to 'threading', 'eventlet' or 'gevent' to force a mode
2- # else, the best mode is selected automatically from what's installed
1+ # set async_mode to 'threading', 'eventlet', 'gevent' or 'gevent_uwsgi' to
2+ # force a mode else, the best mode is selected automatically from what's
3+ # installed
34async_mode = None
45
56import time
@@ -108,5 +109,9 @@ def test_disconnect(sid):
108109 handler_class = WebSocketHandler ).serve_forever ()
109110 else :
110111 pywsgi .WSGIServer (('' , 5000 ), app ).serve_forever ()
112+ elif sio .async_mode == 'gevent_uwsgi' :
113+ print ('Start the application through the uwsgi server. Example:' )
114+ print ('uwsgi --http :5000 --gevent 1000 --http-websockets --master '
115+ '--wsgi-file app.py --callable app' )
111116 else :
112117 print ('Unknown async_mode: ' + sio .async_mode )
Original file line number Diff line number Diff line change 1- from flask import Flask , render_template
1+ # set async_mode to 'threading', 'eventlet', 'gevent' or 'gevent_uwsgi' to
2+ # force a mode else, the best mode is selected automatically from what's
3+ # installed
4+ async_mode = None
25
6+ from flask import Flask , render_template
37import socketio
48
5- # set async_mode to 'threading', 'eventlet' or 'gevent' to force a mode
6- # else, the best mode is selected automatically from what's installed
7- async_mode = None
8-
99sio = socketio .Server (async_mode = async_mode )
1010app = Flask (__name__ )
1111app .wsgi_app = socketio .Middleware (sio , app .wsgi_app )
@@ -43,5 +43,9 @@ def ping(sid):
4343 handler_class = WebSocketHandler ).serve_forever ()
4444 else :
4545 pywsgi .WSGIServer (('' , 5000 ), app ).serve_forever ()
46+ elif sio .async_mode == 'gevent_uwsgi' :
47+ print ('Start the application through the uwsgi server. Example:' )
48+ print ('uwsgi --http :5000 --gevent 1000 --http-websockets --master '
49+ '--wsgi-file latency.py --callable app' )
4650 else :
4751 print ('Unknown async_mode: ' + sio .async_mode )
Original file line number Diff line number Diff line change @@ -37,11 +37,14 @@ class Server(object):
3737
3838 The Engine.IO configuration supports the following settings:
3939
40- :param async_mode: The library used for asynchronous operations. Valid
41- options are "threading", "eventlet" and "gevent". If
42- this argument is not given, "eventlet" is tried first,
43- then "gevent", and finally "threading". The websocket
44- transport is only supported in "eventlet" mode.
40+ :param async_mode: The asynchronous model to use. See the Deployment
41+ section in the documentation for a description of the
42+ available options. Valid async modes are "threading",
43+ "eventlet", "gevent" and "gevent_uwsgi". If this
44+ argument is not given, "eventlet" is tried first, then
45+ "gevent_uwsgi", then "gevent", and finally "threading".
46+ The first async mode that has all its dependencies
47+ installed is then one that is chosen.
4548 :param ping_timeout: The time in seconds that the client waits for the
4649 server to respond before disconnecting.
4750 :param ping_interval: The interval in seconds at which the client pings
You can’t perform that action at this time.
0 commit comments