Last active
August 29, 2015 14:08
-
-
Save ikatson/264ffc6e496854b58015 to your computer and use it in GitHub Desktop.
uwsgi Websocket error: ASYNC call without async mode !!!, IOError: unable to fd to the event queue
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
*.pyc |
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
<!doctype html> | |
<meta charset=utf-8> | |
<title>UWSGI WS test</title> | |
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script> | |
<script> | |
angular.module('app', []).controller('Ctrl', function ($scope) { | |
this.logMessages = []; | |
var self = this; | |
var log = function (msg) { | |
self.logMessages.push({date: new Date(), msg: msg}); | |
$scope.$digest(); | |
} | |
var ws = new WebSocket('ws://localhost:5000/ws/'); | |
ws.onopen = function () { | |
log('WS open'); | |
ws.send('message to server'); | |
} | |
ws.onmessage = function (msg) { | |
log('WS message received: ' + msg); | |
}; | |
ws.onclose = function () { | |
log('WS closed'); | |
}; | |
ws.onerror = function (err) { | |
log('WS error: ' + err); | |
} | |
}); | |
</script> | |
<body ng-app="app" ng-controller="Ctrl as ctrl" class="container"> | |
<h2>uWSGI websocket test</h2> | |
<div ng-repeat="msg in ctrl.logMessages.slice().reverse()"><pre>[{{msg.date|date:'mediumTime'}}]: {{msg.msg}}</pre><div> | |
</body> |
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
gevent>=1.0 | |
uwsgi |
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
import uwsgi | |
def application(env, start_response): | |
if env['PATH_INFO'] != '/ws/': | |
start_response('404 Not Found', []) | |
return | |
uwsgi.websocket_handshake(env['HTTP_SEC_WEBSOCKET_KEY'], env.get('HTTP_ORIGIN', '')) | |
websocket_fd = uwsgi.connection_fd() | |
def process_msg(msg): | |
uwsgi.websocket_send('got %s' % msg) | |
while True: | |
uwsgi.wait_fd_read(websocket_fd, 3) | |
uwsgi.suspend() | |
fd = uwsgi.ready_fd() | |
if fd > -1: | |
if fd == websocket_fd: | |
msg = uwsgi.websocket_recv_nb() | |
if msg: | |
process_msg(msg) | |
else: | |
# on timeout call websocket_recv_nb again to manage ping/pong | |
msg = uwsgi.websocket_recv_nb() | |
if msg: | |
process_msg(msg) |
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] | |
gevent=1000 | |
route = ^/$ static:%dindex.html | |
wsgi=server:application | |
pythonpath=%d | |
pythonhome=$(VIRTUAL_ENV) | |
http=:5000 | |
http-websockets= | |
master= | |
py-autoreload=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment