python-3.x - 带有 AssertionError 的龙卷风 websocket 崩溃
问题描述
当我从 websocket 发送数据时出现一些错误,我认为客户端也在发送数据并与该数据发生冲突
ERROR:tornado.general:Uncaught exception, closing connection.
Traceback (most recent call last):
File "/home/ori/.local/lib/python3.7/site-packages/tornado/iostream.py", line 706, in _handle_events
self._handle_write()
File "/home/ori/.local/lib/python3.7/site-packages/tornado/iostream.py", line 964, in _handle_write
self._write_buffer.advance(num_bytes)
File "/home/ori/.local/lib/python3.7/site-packages/tornado/iostream.py", line 202, in advance
assert 0 < size <= self._size
AssertionError
ERROR:asyncio:Exception in callback None()
handle: <Handle cancelled>
Traceback (most recent call last):
File "/usr/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/home/ori/.local/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 138, in _handle_events
handler_func(fileobj, events)
File "/home/ori/.local/lib/python3.7/site-packages/tornado/iostream.py", line 706, in _handle_events
self._handle_write()
File "/home/ori/.local/lib/python3.7/site-packages/tornado/iostream.py", line 964, in _handle_write
self._write_buffer.advance(num_bytes)
File "/home/ori/.local/lib/python3.7/site-packages/tornado/iostream.py", line 202, in advance
assert 0 < size <= self._size
AssertionError
'NoneType' object has no attribute 'stream'
我认为引起这个问题的代码是
def send_all(message):
for ws in web_socket_clients:
try:
if not ws.ws_connection.stream.socket:
web_socket_clients.remove(ws)
else:
try:
ws.write_message(json.dumps(message))
except AssertionError as a:
pass
except AssertionError:
pass
解决方案
不要ws_connection
直接访问属性;这是不支持的。
相反,在您的处理程序中覆盖on_close并在此时从客户端集中删除。
推荐阅读
- c# - 释放静态 WCF 资源
- python - Python:如何在 mysql 结果头中包含表前缀
- scala - 我需要计算执行时间、成本、制造时间、等待时间等
- amazon-web-services - AWS Cognito Google 身份提供商获取个人资料名字和姓氏
- svg - 如何在 SVG 上设置宽度和高度属性
- c - 如何在字符串中间找到一个字符?
- android - 启用 Proguard 时 Retrofit2 不起作用
- if-statement - 使用 Google Sheet Script 的 If/Then 代码出现问题
- vue.js - 如何为第 3 部分 CSS 启用 PurgeCSS
- java - 有没有办法通过组件扫描查看注册了哪些 Bean?