(self)
| 331 | self.ping_looper.cancel() |
| 332 | |
| 333 | async def ping_loop(self): |
| 334 | if self.verbose: |
| 335 | self.log(iso8601(milliseconds()), 'ping loop') |
| 336 | while self.keepAlive and not self.closed(): |
| 337 | now = milliseconds() |
| 338 | self.lastPong = now if self.lastPong is None else self.lastPong |
| 339 | if (self.lastPong + self.keepAlive * self.maxPingPongMisses) < now: |
| 340 | self.on_error(RequestTimeout('Connection to ' + self.url + ' timed out due to a ping-pong keepalive missing on time')) |
| 341 | # the following ping-clause is not necessary with aiohttp's built-in ws |
| 342 | # since it has a heartbeat option (see create_connection above) |
| 343 | # however some exchanges require a text-type ping message |
| 344 | # therefore we need this clause anyway |
| 345 | else: |
| 346 | if self.ping: |
| 347 | try: |
| 348 | await self.send(self.ping(self)) |
| 349 | except Exception as e: |
| 350 | self.on_error(e) |
| 351 | else: |
| 352 | await self.connection.ping() |
| 353 | await sleep(self.keepAlive / 1000) |
no test coverage detected