3

当我四处搜索时,这似乎是一个常见问题,但我似乎找不到可行的解决方案。据我所知,该错误不是很有帮助,因为它并没有真正告诉您为什么保存的会话消失了。

 Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/eventlet/wsgi.py", line 481, in handle_one_response
    result = self.application(self.environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/flask_socketio/__init__.py", line 37, in __call__
    start_response)
  File "/usr/local/lib/python2.7/dist-packages/engineio/middleware.py", line 47, in __call__
    return self.engineio_app.handle_request(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/socketio/server.py", line 303, in handle_request
    return self.eio.handle_request(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/engineio/server.py", line 226, in handle_request
    environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/engineio/socket.py", line 79, in handle_get_request
    start_response)
  File "/usr/local/lib/python2.7/dist-packages/engineio/socket.py", line 118, in _upgrade_websocket
    return ws(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/engineio/async_eventlet.py", line 13, in __call__
    return super(WebSocketWSGI, self).__call__(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/eventlet/websocket.py", line 127, in __call__
    self.handler(ws)
  File "/usr/local/lib/python2.7/dist-packages/engineio/socket.py", line 180, in _websocket_handler
    self.receive(pkt)
  File "/usr/local/lib/python2.7/dist-packages/engineio/socket.py", line 48, in receive
    self.server._trigger_event('message', self.sid, pkt.data)
  File "/usr/local/lib/python2.7/dist-packages/engineio/server.py", line 330, in _trigger_event
    return self.handlers[event](*args)
  File "/usr/local/lib/python2.7/dist-packages/socketio/server.py", line 429, in _handle_eio_message
    self._handle_event(sid, pkt.namespace, pkt.id, pkt.data)
  File "/usr/local/lib/python2.7/dist-packages/socketio/server.py", line 371, in _handle_event
    r = self._trigger_event(data[0], namespace, sid, *data[1:])
  File "/usr/local/lib/python2.7/dist-packages/socketio/server.py", line 397, in _trigger_event
    return self.handlers[namespace][event](*args)
  File "/usr/local/lib/python2.7/dist-packages/flask_socketio/__init__.py", line 199, in _handler
    self.server.environ[sid]['saved_session'] = {}
KeyError: 'baee47721e474a1a9885b41ee0ce1847'
4

1 回答 1

6

首先,升级以下包:flask-socketio、python-socketio 和 python-engineio。

我认为这将解决您的问题。旧版本的 Flask-SocketIO 会出现此问题。我确定这种情况的原因是处理程序函数(您用socketio.on()装饰器装饰的这些函数)运行了很长时间而没有正确释放 CPU。如果该函数运行超过 60 秒而没有释放 CPU,则系统错误地认为客户端已离开并断开会话,导致稍后访问该会话时出现 KeyError。

该错误已在最新版本中得到解决。但也请确保释放 CPU,以便在后台运行的其他任务有机会执行他们需要执行的操作。

于 2016-06-28T20:10:39.760 回答