websocket.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:octoclient 作者: hroncok 项目源码 文件源码
def run(self):
        """
        Runs thread, which listens on socket.
        Executes given callbacks on events
        """
        def on_message(ws, data):
            if data.startswith('m'):
                self.on_message(ws, json.loads(data[1:]))
            elif data.startswith('a'):
                for msg in json.loads(data[1:]):
                    self.on_message(ws, msg)

        self.socket = websocket.WebSocketApp(self.url,
                                             on_open=self.on_open,
                                             on_close=self.on_close,
                                             on_message=on_message)
        self.thread = Thread(target=self.socket.run_forever)
        self.thread.daemon = True
        self.thread.start()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号