向所有套接字发送响应时,龙卷风断言错误

时间:2018-08-24 11:59:34

标签: tornado

我们正在从UDP套接字接收股票数据,然后使用Tornado套接字连接将其重播到浏览器。

但是,有时会尝试发送以下错误,但遇到以下错误。是什么原因造成的?

12346 ERROR:2018-08-24 01:01:59,202:get_broadcast
12347 Traceback (most recent call last):
12348   File "/release/manik/muTrade-1.0.0-1.7.4.5/web/utrade/WebSocket/get_broadcast.py", line 321, in _send_msg_to_clients
12349     socketConnectionObject.send(smart_str(simplejson.dumps(data)))
12350   File "/release/st01/py3Env/lib/python3.6/site-packages/sockjs/tornado/conn.py", line 49, in send
12351     self.session.send_message(message, binary=binary)
12352   File "/release/st01/py3Env/lib/python3.6/site-packages/sockjs/tornado/session.py", line 322, in send_message
12353     self.send_jsonified(proto.json_encode(bytes_to_str(msg)), stats)
12354   File "/release/st01/py3Env/lib/python3.6/site-packages/sockjs/tornado/session.py", line 337, in send_jsonified
12355     self.handler.send_pack('a[%s]' % msg)
12356   File "/release/st01/py3Env/lib/python3.6/site-packages/sockjs/tornado/transports/websocket.py", line 86, in send_pack
12357     self.write_message(message, binary)
12358   File "/release/st01/py3Env/lib/python3.6/site-packages/tornado/websocket.py", line 252, in write_message
12359     return self.ws_connection.write_message(message, binary=binary)
12360   File "/release/st01/py3Env/lib/python3.6/site-packages/tornado/websocket.py", line 783, in write_message
12361     message = self._compressor.compress(message)
12362   File "/release/st01/py3Env/lib/python3.6/site-packages/tornado/websocket.py", line 548, in compress
12363     assert data.endswith(b'\x00\x00\xff\xff')
12364 AssertionError

编辑:

还收到许多其他错误,详细信息在此[thread] [1]

1:https://github.com/tornadoweb/tornado/issues/2479

1 个答案:

答案 0 :(得分:1)

这是由于多个线程引起的。我将socketclientobjects(在与龙卷风建立新连接时创建)存储在列表中,并在其他线程中使用它们来发送消息。

我删除了socketObject.send(simplejson.dumps(msg)),它直接在线程内部被调用

tornado.ioloop.IOLoop.current().add_callback( socketObject.send, simplejson.dumps(msg))

,一切开始正常。我收到多个错误,所有错误都得到解决。