gpt4 book ai didi

websocket 启动时的 django channel 错误消息 (Sessions.py)

转载 作者:行者123 更新时间:2023-12-04 17:41:53 25 4
gpt4 key购买 nike

每当我启动我的 django channel websocket 时。我明白了:

2019-01-10 00:24:09,463 - WARNING - server - Application instance <Task pending coro=<SessionMiddlewareInstance.__call__() running at C:\Users\JAYK~1\Envs\jyst\lib\site-packages\channels\sessions.py:175> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x000001B067F32E58>()]>> for connection <WebSocketProtocol client=['127.0.0.1', 57367] path=b'/jysts/m/KIDA_TG'> took too long to shut down and was killed.

最佳答案

我的应用程序提出了与问题中所述相同的警告。一段时间后,它会杀死 asgi 应用程序,并且在我手动重新启动服务之前无法再连接到 Websocket。

对我来说,它是将 raise StopConsumer() 添加到断开连接函数:

def disconnect(self, close_code):
# Leave room group
async_to_sync(self.channel_layer.group_discard)(
self.room_group_name,
self.channel_name
)
raise StopConsumer()

As stated by the Channel Documentation:"you need to raise channels.exceptions.StopConsumer to halt the ASGI application cleanly and let the server clean it up. If you leave it running - by not raising this exception - the server will reach its application close timeout (which is 10 seconds by default in Daphne) and then kill your application and raise a warning."

关于websocket 启动时的 django channel 错误消息 (Sessions.py),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54119968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com