我基于sockjs-tornado聊天样本开发即时消息应用程序。我的代码是异步的。
拥有此堆栈跟踪:
ERROR:root:Exception in callback <tornado.stack_context._StackContextWrapper object at 0x80932c788>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/tornado/ioloop.py", line 421, in _run_callback
callback()
File "/usr/local/lib/python2.7/site-packages/tornado/iostream.py", line 305, in wrapper
callback(*args)
File "/usr/local/lib/python2.7/site-packages/sockjs/tornado/websocket.py", line 661, in _on_frame_data
self._receive_frame()
File "/usr/local/lib/python2.7/site-packages/sockjs/tornado/websocket.py", line 580, in _receive_frame
self.stream.read_bytes(2, self._on_frame_start)
File "/usr/local/lib/python2.7/site-packages/tornado/iostream.py", line 166, in read_bytes
self._try_inline_read()
File "/usr/local/lib/python2.7/site-packages/tornado/iostream.py", line 382, in _try_inline_read
self._check_closed()
File "/usr/local/lib/python2.7/site-packages/tornado/iostream.py", line 565, in _check_closed
raise IOError("Stream is closed")
IOError: Stream is closed
如果我必须从聊天参与者列表中删除对已关闭连接的引用,处理此异常的方法是什么?
由于
答案 0 :(得分:0)
当用户在没有正确关闭websocket连接的情况下丢弃(网络错误等)时会发生此异常。
在任何一种情况下,都会调用您的on_close
处理程序,以便您可以从聊天参与者列表中删除用户。