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()
评论列表
文章目录