{"action":"created","issue":{"url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/issues/381","repository_url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO","labels_url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/issues/381/labels{/name}","comments_url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/issues/381/comments","events_url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/issues/381/events","html_url":"https://github.com/miguelgrinberg/Flask-SocketIO/issues/381","id":195508708,"number":381,"title":"Run error with uwsgi and gevent","user":{"login":"wwqgtxx","id":582584,"avatar_url":"https://avatars.githubusercontent.com/u/582584?v=3","gravatar_id":"","url":"https://api.github.com/users/wwqgtxx","html_url":"https://github.com/wwqgtxx","followers_url":"https://api.github.com/users/wwqgtxx/followers","following_url":"https://api.github.com/users/wwqgtxx/following{/other_user}","gists_url":"https://api.github.com/users/wwqgtxx/gists{/gist_id}","starred_url":"https://api.github.com/users/wwqgtxx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wwqgtxx/subscriptions","organizations_url":"https://api.github.com/users/wwqgtxx/orgs","repos_url":"https://api.github.com/users/wwqgtxx/repos","events_url":"https://api.github.com/users/wwqgtxx/events{/privacy}","received_events_url":"https://api.github.com/users/wwqgtxx/received_events","type":"User","site_admin":false},"labels":[{"id":347047376,"url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/labels/investigate","name":"investigate","color":"fbca04","default":false}],"state":"open","locked":false,"assignee":{"login":"miguelgrinberg","id":2715854,"avatar_url":"https://avatars.githubusercontent.com/u/2715854?v=3","gravatar_id":"","url":"https://api.github.com/users/miguelgrinberg","html_url":"https://github.com/miguelgrinberg","followers_url":"https://api.github.com/users/miguelgrinberg/followers","following_url":"https://api.github.com/users/miguelgrinberg/following{/other_user}","gists_url":"https://api.github.com/users/miguelgrinberg/gists{/gist_id}","starred_url":"https://api.github.com/users/miguelgrinberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miguelgrinberg/subscriptions","organizations_url":"https://api.github.com/users/miguelgrinberg/orgs","repos_url":"https://api.github.com/users/miguelgrinberg/repos","events_url":"https://api.github.com/users/miguelgrinberg/events{/privacy}","received_events_url":"https://api.github.com/users/miguelgrinberg/received_events","type":"User","site_admin":false},"assignees":[{"login":"miguelgrinberg","id":2715854,"avatar_url":"https://avatars.githubusercontent.com/u/2715854?v=3","gravatar_id":"","url":"https://api.github.com/users/miguelgrinberg","html_url":"https://github.com/miguelgrinberg","followers_url":"https://api.github.com/users/miguelgrinberg/followers","following_url":"https://api.github.com/users/miguelgrinberg/following{/other_user}","gists_url":"https://api.github.com/users/miguelgrinberg/gists{/gist_id}","starred_url":"https://api.github.com/users/miguelgrinberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miguelgrinberg/subscriptions","organizations_url":"https://api.github.com/users/miguelgrinberg/orgs","repos_url":"https://api.github.com/users/miguelgrinberg/repos","events_url":"https://api.github.com/users/miguelgrinberg/events{/privacy}","received_events_url":"https://api.github.com/users/miguelgrinberg/received_events","type":"User","site_admin":false}],"milestone":null,"comments":20,"created_at":"2016-12-14T11:38:23Z","updated_at":"2016-12-17T04:13:47Z","closed_at":null,"body":"When I run my flask app with uwsgi and gevent,It always throw those exception\r\n```\r\n20:20:30{engineio}socket.py[line:44]<receive> b'uWSGIWorker1Core0' INFO : d6a02d68ab4e4b9688186077ba4164a2: Received packet MESSAGE data 2/debug,[\"move\",{\"which\":\"X\",\"dir\":\"up\",\"speed\":\"\",\"length\":\"\"}]\r\n20:20:30{socketio}server.py[line:443]<_handle_event> b'uWSGIWorker1Core0' INFO : received event \"move\" from d6a02d68ab4e4b9688186077ba4164a2 [/debug]\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.4/dist-packages/flask/app.py\", line 2000, in __call__\r\n    return self.wsgi_app(environ, start_response)\r\n  File \"/usr/local/lib/python3.4/dist-packages/flask_socketio/__init__.py\", line 41, in __call__\r\n    start_response)\r\n  File \"/usr/local/lib/python3.4/dist-packages/engineio/middleware.py\", line 47, in __call__\r\n    return self.engineio_app.handle_request(environ, start_response)\r\n  File \"/usr/local/lib/python3.4/dist-packages/socketio/server.py\", line 352, in handle_request\r\n    return self.eio.handle_request(environ, start_response)\r\n  File \"/usr/local/lib/python3.4/dist-packages/engineio/server.py\", line 241, in handle_request\r\n    environ, start_response)\r\n  File \"/usr/local/lib/python3.4/dist-packages/engineio/socket.py\", line 81, in handle_get_request\r\n    start_response)\r\n  File \"/usr/local/lib/python3.4/dist-packages/engineio/socket.py\", line 122, in _upgrade_websocket\r\n    return ws(environ, start_response)\r\n  File \"/usr/local/lib/python3.4/dist-packages/engineio/async_gevent_uwsgi.py\", line 58, in __call__\r\n    return self.app(self)\r\n  File \"/usr/local/lib/python3.4/dist-packages/engineio/socket.py\", line 188, in _websocket_handler\r\n    self.receive(pkt)\r\n  File \"/usr/local/lib/python3.4/dist-packages/engineio/socket.py\", line 50, in receive\r\n    async=self.server.async_handlers)\r\n  File \"/usr/local/lib/python3.4/dist-packages/engineio/server.py\", line 359, in _trigger_event\r\n    return self.handlers[event](*args)\r\n  File \"/usr/local/lib/python3.4/dist-packages/socketio/server.py\", line 509, in _handle_eio_message\r\n    self._handle_event(sid, pkt.namespace, pkt.id, pkt.data)\r\n  File \"/usr/local/lib/python3.4/dist-packages/socketio/server.py\", line 448, in _handle_event\r\n    self._handle_event_internal(self, sid, data, namespace, id)\r\n  File \"/usr/local/lib/python3.4/dist-packages/socketio/server.py\", line 451, in _handle_event_internal\r\n    r = server._trigger_event(data[0], namespace, sid, *data[1:])\r\n  File \"/usr/local/lib/python3.4/dist-packages/socketio/server.py\", line 480, in _trigger_event\r\n    return self.handlers[namespace][event](*args)\r\n  File \"/usr/local/lib/python3.4/dist-packages/flask_socketio/__init__.py\", line 221, in _handler\r\n    *args)\r\n  File \"/usr/local/lib/python3.4/dist-packages/flask_socketio/__init__.py\", line 575, in _handle_event\r\n    app = self.server.environ[sid]['flask.app']\r\nKeyError: 'flask.app'\r\n\r\n```\r\nAnd\r\n```\r\n[pid: 17560|app: 0|req: 19/18] 192.168.1.100 () {40 vars in 878 bytes} [Wed Dec 14 20:19:18 2016] GET / => generated 2912 bytes in 12 msecs (HTTP/1.1 200) 4 headers in 242 bytes (3 switches on core 999)\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.4/dist-packages/flask/app.py\", line 2000, in __call__\r\n    return self.wsgi_app(environ, start_response)\r\n  File \"/usr/local/lib/python3.4/dist-packages/flask_socketio/__init__.py\", line 41, in __call__\r\n    start_response)\r\n  File \"/usr/local/lib/python3.4/dist-packages/engineio/middleware.py\", line 47, in __call__\r\n    return self.engineio_app.handle_request(environ, start_response)\r\n  File \"/usr/local/lib/python3.4/dist-packages/socketio/server.py\", line 352, in handle_request\r\n    return self.eio.handle_request(environ, start_response)\r\n  File \"/usr/local/lib/python3.4/dist-packages/engineio/server.py\", line 279, in handle_request\r\n    start_response(r['status'], r['headers'] + cors_headers)\r\nOSError: headers already sent\r\n\r\n```\r\nI'm only use the code like this\r\n```\r\napp = Flask(__name__)\r\napp.secret_key = os.urandom(24)\r\nsocketio = SocketIO(app, async_mode=\"gevent_uwsgi\")\r\n```\r\nAnd start my program by\r\n```\r\nuwsgi --http 0.0.0.0:8070 --chdir /ST --gevent 1000 --http-websockets --master --wsgi-file server.py --callable app\r\n```\r\nthe uwsgi's start info is\r\n```\r\n*** Starting uWSGI 2.0.14 (32bit) on [Wed Dec 14 19:10:34 2016] ***\r\ncompiled with version: 4.9.2 on 14 December 2016 16:29:43\r\nos: Linux-4.4.34-v7+ #930 SMP Wed Nov 23 15:20:41 GMT 2016\r\nnodename: raspberrypi\r\nmachine: armv7l\r\nclock source: unix\r\npcre jit disabled\r\ndetected number of CPU cores: 4\r\ncurrent working directory: /\r\ndetected binary path: /usr/local/bin/uwsgi\r\nuWSGI running as root, you can use --uid/--gid/--chroot options\r\n*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***\r\nchdir() to /ST\r\nyour processes number limit is 7336\r\nyour memory page size is 4096 bytes\r\ndetected max file descriptor number: 65536\r\n- async cores set to 1000 - fd table size: 65536\r\nlock engine: pthread robust mutexes\r\nthunder lock: disabled (you can enable it with --thunder-lock)\r\nuWSGI http bound on 0.0.0.0:8070 fd 4\r\nuwsgi socket 0 bound to TCP address 127.0.0.1:46388 (port auto-assigned) fd 3\r\nPython version: 3.4.2 (default, Oct 19 2014, 14:03:53)  [GCC 4.9.1]\r\nPython main interpreter initialized at 0x14f5558\r\npython threads support enabled\r\nyour server socket listen backlog is limited to 100 connections\r\nyour mercy for graceful operations on workers is 60 seconds\r\nmapped 14961664 bytes (14611 KB) for 1000 cores\r\n*** Operational MODE: async ***\r\n```\r\nIf I run this code without uwsgi and set async_code to eventlet,every thing work well.\r\nPlease help me found the reason.\r\nThanks"},"comment":{"url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/issues/comments/267742105","html_url":"https://github.com/miguelgrinberg/Flask-SocketIO/issues/381#issuecomment-267742105","issue_url":"https://api.github.com/repos/miguelgrinberg/Flask-SocketIO/issues/381","id":267742105,"user":{"login":"wwqgtxx","id":582584,"avatar_url":"https://avatars.githubusercontent.com/u/582584?v=3","gravatar_id":"","url":"https://api.github.com/users/wwqgtxx","html_url":"https://github.com/wwqgtxx","followers_url":"https://api.github.com/users/wwqgtxx/followers","following_url":"https://api.github.com/users/wwqgtxx/following{/other_user}","gists_url":"https://api.github.com/users/wwqgtxx/gists{/gist_id}","starred_url":"https://api.github.com/users/wwqgtxx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wwqgtxx/subscriptions","organizations_url":"https://api.github.com/users/wwqgtxx/orgs","repos_url":"https://api.github.com/users/wwqgtxx/repos","events_url":"https://api.github.com/users/wwqgtxx/events{/privacy}","received_events_url":"https://api.github.com/users/wwqgtxx/received_events","type":"User","site_admin":false},"created_at":"2016-12-17T04:13:46Z","updated_at":"2016-12-17T04:13:46Z","body":"I know that I call a init() function write by myself in connect().It cause connect() be so slow to cause this websocket connect timeout.I think the uwsgi may be has some time limit for a websocket parse time to cause this problem.\r\nBut I call init() function in connect because the falsk-websocket don't call flask's app.before_first_request function and also not provide the similar function to init the app."}}
{"actor":{"display_login":"wwqgtxx"}}