MCPcopy
hub / github.com/tornadoweb/tornado / periodic_ping

Method periodic_ping

tornado/websocket.py:1354–1385  ·  view source on GitHub ↗

Send a ping and wait for a pong if ping_timeout is configured. Called periodically if the websocket_ping_interval is set and non-zero.

(self)

Source from the content-addressed store, hash-verified

1352 return max(0, last_ping_time + interval - now)
1353
1354 async def periodic_ping(self) -> None:
1355 """Send a ping and wait for a pong if ping_timeout is configured.
1356
1357 Called periodically if the websocket_ping_interval is set and non-zero.
1358 """
1359 interval = self.ping_interval
1360 timeout = self.ping_timeout
1361
1362 await asyncio.sleep(interval)
1363
1364 while True:
1365 # send a ping
1366 self._received_pong = False
1367 ping_time = IOLoop.current().time()
1368 self.write_ping(b"")
1369
1370 # wait until the ping timeout
1371 await asyncio.sleep(timeout)
1372
1373 # make sure we received a pong within the timeout
1374 if timeout > 0 and not self._received_pong:
1375 self.close(reason="ping timed out")
1376 return
1377
1378 # wait until the next scheduled ping
1379 await asyncio.sleep(
1380 self.ping_sleep_time(
1381 last_ping_time=ping_time,
1382 interval=interval,
1383 now=IOLoop.current().time(),
1384 )
1385 )
1386
1387
1388class WebSocketClientConnection(simple_httpclient._HTTPConnection):

Callers 1

start_pingingMethod · 0.95

Calls 5

write_pingMethod · 0.95
closeMethod · 0.95
ping_sleep_timeMethod · 0.95
timeMethod · 0.80
currentMethod · 0.80

Tested by

no test coverage detected