websockets.py 文件源码

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

项目:socketshark 作者: closeio 项目源码 文件源码
def ping_handler(self):
        ping_interval = self.shark.config['WS_PING']['interval']
        if not ping_interval:
            return
        latency = 0
        while True:
            await asyncio.sleep(ping_interval - latency)
            self.session.log.debug('ping')
            start_time = time.time()
            try:
                ping = await self.websocket.ping()
            except websockets.ConnectionClosed:
                return
            timeout_handler = asyncio.ensure_future(
                    self.ping_timeout_handler(ping))
            await ping
            latency = time.time() - start_time
            self.session.log.debug('pong', latency=round(latency, 3))
            # Return immediately if a ping timeout occurred.
            if not timeout_handler.cancel() and timeout_handler.result():
                return
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号