Send a ping to keep the websocket alive Called periodically if the websocket_ping_interval is set and non-zero.
(self)
| 1314 | self.ping_callback.start() |
| 1315 | |
| 1316 | def periodic_ping(self) -> None: |
| 1317 | """Send a ping to keep the websocket alive |
| 1318 | |
| 1319 | Called periodically if the websocket_ping_interval is set and non-zero. |
| 1320 | """ |
| 1321 | if self.is_closing() and self.ping_callback is not None: |
| 1322 | self.ping_callback.stop() |
| 1323 | return |
| 1324 | |
| 1325 | # Check for timeout on pong. Make sure that we really have |
| 1326 | # sent a recent ping in case the machine with both server and |
| 1327 | # client has been suspended since the last ping. |
| 1328 | now = IOLoop.current().time() |
| 1329 | since_last_pong = now - self.last_pong |
| 1330 | since_last_ping = now - self.last_ping |
| 1331 | assert self.ping_interval is not None |
| 1332 | assert self.ping_timeout is not None |
| 1333 | if ( |
| 1334 | since_last_ping < 2 * self.ping_interval |
| 1335 | and since_last_pong > self.ping_timeout |
| 1336 | ): |
| 1337 | self.close() |
| 1338 | return |
| 1339 | |
| 1340 | self.write_ping(b"") |
| 1341 | self.last_ping = now |
| 1342 | |
| 1343 | def set_nodelay(self, x: bool) -> None: |
| 1344 | self.stream.set_nodelay(x) |
nothing calls this directly
no test coverage detected