Flask-sockets Room 实现和连续数据包更新

问题描述

我正在尝试使用 Flask 套接字每 10 秒向客户端发送有关条件更新的连续更新。

不过我遇到了一个问题。我似乎无法创建一个新线程,并且在任何地方都没有可用于为不同输入设置拆分空间的文档

@sockets.route('/updates/<partnumber>')
def echo(ws,partnumber):
    app.logger.info("Connection accepted")
    
    while not ws.closed:
        message = ws.receive()
        print("partnumber " + partnumber)
        if message is None: # message is "None" if the client has closed.
            continue

       # Send the message to all clients connected to this webserver
       # process. (To support multiple processes or instances,an
       # extra-instance storage or messaging system would be required.)
        clients = ws.handler.server.clients.values()

        for client in clients:
            client.ws.send(str(cc.get_last_status(partnumber=partnumber)))

这是我上面的代码。我不确定如何为不同的部件号执行多个进程,或者基本上在连接处于活动状态时将其作为单独的线程在后台运行。希望得到一些帮助。

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)