Created
January 10, 2014 13:10
-
-
Save squeaky-pl/8351684 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# uwsgi --module uwsgiws --callable application --master --http :8080 --http-websockets --gevent 100 | |
# this works | |
import uwsgi | |
from gevent.monkey import patch_all | |
patch_all() | |
def application(env, start_response): | |
# complete the handshake | |
uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env.get('HTTP_ORIGIN', '')) | |
print('shake') | |
while True: | |
msg = uwsgi.websocket_recv() | |
print(msg) | |
uwsgi.websocket_send(msg) | |
# ---------------------------------- | |
# this doesnt | |
Fri Jan 10 14:09:58 2014 - ASYNC call without async mode !!! | |
Traceback (most recent call last): | |
File "./uwsgiws2.py", line 14, in application | |
uwsgi.wait_fd_read(fd) | |
IOError: unable to fd 6 to the event queue | |
[pid: 11138|app: 0|req: 1/1] 127.0.0.1 () {42 vars in 637 bytes} [Fri Jan 10 14:09:58 2014] GET / => generated 0 bytes in 0 msecs (HTTP/1.1 101) 4 headers in 184 bytes (1 switches on core 99) | |
import uwsgi | |
from gevent.monkey import patch_all | |
patch_all() | |
def application(env, start_response): | |
# complete the handshake | |
uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env.get('HTTP_ORIGIN', '')) | |
print('shake') | |
fd = uwsgi.connection_fd() | |
while True: | |
uwsgi.wait_fd_read(fd) | |
uwsgi.suspend() | |
msg = uwsgi.websocket_recv_nb() | |
print(msg) | |
uwsgi.websocket_send(msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment