【问题标题】:django channels error message on websocket start (Sessions.py)websocket启动时的django通道错误消息(Sessions.py)
【发布时间】:2019-06-04 19:24:05
【问题描述】:

每当我启动我的 django 频道 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.

【问题讨论】:

  • 发布您的消费者和路由代码
  • 我通过添加 StopConsumer() 解决了这个问题,谢谢。
  • 你在哪里添加StopConsumer() ??我有同样的问题。
  • stackoverflow.com/questions/53445286/… 请参考这里。你应该在断开连接时提高它

标签: django websocket real-time django-channels


【解决方案1】:

我的申请提出了与问题中所述相同的警告。一段时间后,它会杀死 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()

Channel Documentation 所述: “您需要引发 channels.exceptions.StopConsumer 以干净地停止 ASGI 应用程序并让服务器清理它。如果您让它运行 - 通过不引发此异常 - 服务器将达到其应用程序关闭超时(即在 Daphne 中默认为 10 秒),然后终止您的应用程序并发出警告。”

【讨论】:

    猜你喜欢
    • 2020-05-07
    • 2017-01-25
    • 2018-09-01
    • 2017-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-15
    相关资源
    最近更新 更多