我正在使用streamlit hello示例应用程序测试tornado websocket api,
我向tornado.websocket.WebSocketHandler get方法添加了一个异步包装器来记录websocket连接
# pip3 install streamlit
# streamlit already have inbuilt example hello
# you can start it by streamlit hello
#create a async wrapper
def async_wrapper(original):
async def wrapper(*args, **kwargs):
try:
print("websocket connection")
res = await original(*args,**kwargs)
return res
except Exception as exc:
raise exc
return wrapper
# copy paste the above code in tornado.websocket file and add decorator @async_wrapper to get method
对我来说,异步包装器没有获取任何对象,并且抛出 NonType object not waitable 错误
2024-02-05 17:59:39.786 Uncaught exception GET /_stcore/stream (::1)
HTTPServerRequest(protocol='http', host='localhost:8501', method='GET', uri='/_stcore/stream', version='HTTP/1.1', remote_ip='::1')
Traceback (most recent call last):
File "/env/lib/python3.10/site-packages/tornado/web.py", line 1790, in _execute
result = await result
File "wrapper.py", line 157, in wrapper
raise exc
File "wrapper.py", line 146, in wrapper
res = await original(*args, **kwargs)
File "/env/lib/python3.10/site-packages/tornado/websocket.py", line 273, in get
await self.ws_connection.accept_connection(self)
File "/env/lib/python3.10/site-packages/tornado/websocket.py", line 863, in accept_connection
await self._accept_connection(handler)
File "/env/lib/python3.10/site-packages/tornado/websocket.py", line 946, in _accept_connection
await self._receive_frame_loop()
File "/env/lib/python3.10/site-packages/tornado/websocket.py", line 1102, in _receive_frame_loop
await self._receive_frame()
File "/env/lib/python3.10/site-packages/tornado/websocket.py", line 1193, in _receive_frame
await handled_future
TypeError: object NoneType can't be used in 'await' expression
任何人都可以解释一下问题是什么吗
由于它不是异步的,因此删除
await
关键字:
original(*args,**kwargs)