bot.py 文件源码

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

项目:travisbot 作者: greut 项目源码 文件源码
def run(self):
        """Run the bot."""
        with ClientSession() as session:
            url = self.url + "?"
            url += urlencode({"v": self.API_VERSION, "encoding": json})
            while not self.running.done():
                print("Bot is connecting...")
                self.ws_running = asyncio.Future()
                async with session.ws_connect(url) as ws:
                    self.ws = ws
                    while not self.running.done():
                        # Reading the message.
                        data = await self._receive()
                        if not data:
                            break

                        await self._handle(data)

                        # Cleanup
                        self.futures = [f
                                        for f in self.futures if not f.done()]

                    # Close the tasks
                    # Wait for them.
                    print("Bot is closing...")
                    self.ws_running.cancel()
                    while self.futures:
                        try:
                            await asyncio.gather(*self.futures)
                        except CancelledError:
                            pass
                        self.futures = [f
                                        for f in self.futures if not f.done()]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号