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