This commit is contained in:
yumoqing 2024-10-09 18:54:51 +08:00
parent 4f97384455
commit e9f33f6a45

View File

@ -216,18 +216,23 @@ class WebsocketProcessor(PythonScriptProcessor):
lenv.update(params)
params_kw = lenv.params_kw
userid = lenv.params_kw.userid or await lenv.get_user()
debug(f'========== debug ===========')
del lenv['request']
txt = await self.loadScript(self.real_path)
ws = web.WebSocketResponse()
debug(f'========== debug ===========')
try:
await ws.prepare(request)
except Exception as e:
print('--------except:', e, type(e))
exception(f'--------except: {e}'))
print_exc()
raise e
debug(f'========== debug ===========')
ws_pool = WsPool(ws, request['client_ip'], request.path, request.app)
debug(f'========== debug ===========')
async for msg in ws:
if msg.type == aiohttp.WSMsgType.TEXT:
debug(f'========== {msg=} ===========')
if msg.data == 'exit':
break
debug(f'WS:msg from client={msg}')
@ -237,11 +242,11 @@ class WebsocketProcessor(PythonScriptProcessor):
func = lenv['myfunc']
resp = await func(request,**lenv)
elif msg.type == aiohttp.WSMsgType.ERROR:
info('ws connection closed with exception %s' % ws.exception())
error('ws connection closed with exception %s' % ws.exception())
break
else:
info('datatype error', msg.type)
info(f'========== ws connection end ===========')
debug(f'========== ws connection end ===========')
ws_pool.delete_me()
self.retResponse = ws
await ws.close()