(self, data: str, *, current_depth: int = 0, max_depth=0)
| 336 | ) |
| 337 | |
| 338 | def _send_recursive(self, data: str, *, current_depth: int = 0, max_depth=0): |
| 339 | try: |
| 340 | self.websocket.send(data) |
| 341 | except Exception: |
| 342 | if current_depth < max_depth: |
| 343 | sleep_duration = self._PACKET_FAILURE_SLEEPDURATIONS[ |
| 344 | min(current_depth, len(self._PACKET_FAILURE_SLEEPDURATIONS) - 1) |
| 345 | ] |
| 346 | time.sleep(sleep_duration) |
| 347 | self.connect() |
| 348 | time.sleep(sleep_duration) |
| 349 | self._send_recursive(data, current_depth=current_depth + 1, max_depth=max_depth) |
| 350 | else: |
| 351 | self.active_connection = False |
| 352 | raise exceptions.CloudConnectionError(f"Sending packet failed {max_depth + 1} tries: {data}") |
| 353 | |
| 354 | def _send_packet(self, packet, *, max_retries=2): |
| 355 | self._send_recursive(json.dumps(packet) + "\n", max_depth=max_retries) |
no test coverage detected