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

标签 django websocket real-time django-channels

每当我启动我的 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/

相关文章:

django - 在 Django 中实现多个管理级别

python - 如何在 django 中使用 South 将 CharField 替换为foreignkey?

python - 在 Flutter 中显示来自 websocket 的字节的实时视频

WebSocket 连接和 Tritium

websocket - SignalR 不在 IIS Express 10 上使用 websockets

javascript - 浏览器如何以及何时对文档的 DOM 实现实时更改?

c++ - Linux 上 HTML Web 客户端的 QT REST 开发

django - Django 中的上下文是什么?

python - Django - 在 ModelForm 中添加密码验证

performance - Haskell 对于游戏等软实时应用程序的 GC 性能如何?