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
428
428
python-socketio does not require monkey patching, other libraries such as
429
429
database drivers are likely to require it.
430
430
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
+
431
454
Standard Threading Library
432
455
~~~~~~~~~~~~~~~~~~~~~~~~~~
433
456
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
3
4
async_mode = None
4
5
5
6
import time
@@ -108,5 +109,9 @@ def test_disconnect(sid):
108
109
handler_class = WebSocketHandler ).serve_forever ()
109
110
else :
110
111
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' )
111
116
else :
112
117
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
2
5
6
+ from flask import Flask , render_template
3
7
import socketio
4
8
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
-
9
9
sio = socketio .Server (async_mode = async_mode )
10
10
app = Flask (__name__ )
11
11
app .wsgi_app = socketio .Middleware (sio , app .wsgi_app )
@@ -43,5 +43,9 @@ def ping(sid):
43
43
handler_class = WebSocketHandler ).serve_forever ()
44
44
else :
45
45
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' )
46
50
else :
47
51
print ('Unknown async_mode: ' + sio .async_mode )
Original file line number Diff line number Diff line change @@ -37,11 +37,14 @@ class Server(object):
37
37
38
38
The Engine.IO configuration supports the following settings:
39
39
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.
45
48
:param ping_timeout: The time in seconds that the client waits for the
46
49
server to respond before disconnecting.
47
50
:param ping_interval: The interval in seconds at which the client pings
You can’t perform that action at this time.
0 commit comments