这是我第一个使用 Tornado 的项目......使用 TornadIO + ZMQ 构建消息服务。我正在使用 pyzmq 的 ioloop。我一直在遇到 iostream 和 websocket 之间的递归循环问题,但还不能确定原因。似乎客户端连接良好并发送大量消息并接收良好。其他人连接并且没问题然后崩溃。我不知道我是否没有正确处理断开连接,或者消息中的某些内容是否导致龙卷风代码中的读取错误。我的服务器中真正发生的事情是客户端连接并发送消息,然后将这些消息广播给也通过 websocket 连接的其他所有人。
也许有人可以告诉我这里到底发生了什么,如果我处理不当……
// 开始回溯...
[E 110426 01:45:28 ioloop:295] Exception in I/O handler for fd 22
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/pyzmq-2.1.4-py2.6-linux-x86_64.egg/zmq/eventloop/ioloop.py", line 282, in start
self._handlers[fd](fd, events)
File "/usr/local/lib/python2.6/dist-packages/pyzmq-2.1.4-py2.6-linux-x86_64.egg/zmq/eventloop/stack_context.py", line 133, in wrapped
callback(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/iostream.py", line 199, in _handle_events
self._handle_read()
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/iostream.py", line 258, in _handle_read
if self._read_from_buffer():
// START:递归循环的块
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/iostream.py", line 325, in _read_from_buffer
self._consume(loc + delimiter_len))
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/iostream.py", line 230, in _run_callback
callback(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/stack_context.py", line 173, in wrapped
callback(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/websocket.py", line 193, in _on_end_delimiter
self._receive_message()
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/websocket.py", line 178, in _receive_message
self.stream.read_bytes(1, self._on_frame_type)
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/iostream.py", line 149, in read_bytes
if self._read_from_buffer():
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/iostream.py", line 314, in _read_from_buffer
self._run_callback(callback, self._consume(num_bytes))
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/iostream.py", line 230, in _run_callback
callback(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/stack_context.py", line 173, in wrapped
callback(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/websocket.py", line 183, in _on_frame_type
self.stream.read_until("\xff", self._on_end_delimiter)
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/iostream.py", line 133, in read_until
if self._read_from_buffer():
// 循环返回开始(iostream 中的第 325 行)
有什么帮助吗??????我在 ubuntu linux 上使用 pypi tornado 1.2.1、tornadIO 0.0.4、zeromq 2.1.4 和 pypi pyzmq
编辑:它似乎来自我的 on_close() 处理程序中的这个片段:
if self._client_sub and self._client_sub.stream:
try:
self._client_sub.stream.stop_on_recv()
self._client_sub.stream.stop_on_err()
except Exception, e:
logging.error("Failed to close stream and sub socket on client disconnect", exc_info=True)
这是回溯:
[E 110425 20:52:50 messgr:202] Failed to close stream and sub socket on client disconnect
Traceback (most recent call last):
File "messgr.py", line 198, in on_close
try:
AttributeError: 'NoneType' object has no attribute 'stream'
Traceback (most recent call last):
File "/usr/lib/python2.6/logging/init.py", line 776, in emit
msg = self.format(record)
File "/usr/lib/python2.6/logging/init.py", line 654, in format
return fmt.format(record)
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2.1-py2.6.egg/tornado/options.py", line 362, in format
record.exc_text = self.formatException(record.exc_info)
File "/usr/lib/python2.6/logging/init.py", line 416, in formatException
traceback.print_exception(ei[0], ei[1], ei[2], None, sio)
File "/usr/lib/python2.6/traceback.py", line 125, in print_exception
print_tb(tb, limit, file)
File "/usr/lib/python2.6/traceback.py", line 69, in print_tb
line = linecache.getline(filename, lineno, f.f_globals)
File "/usr/lib/python2.6/linecache.py", line 14, in getline
lines = getlines(filename, module_globals)
File "/usr/lib/python2.6/linecache.py", line 40, in getlines
return updatecache(filename, module_globals)
发生的事情是回溯发生了一次。然后它似乎堆叠起来,发生了两次,然后是 3 次......无休止。