_ensure_active_connection

pydoll · realtime, websocket-connection, reconnection-handling, connection-health, infra

Checks if the current WebSocket connection is healthy and establishes a new one if not, ensuring reliable communication.

    async def _ensure_active_connection(self):
        """Ensure a healthy connection exists, establishing a new one if needed."""
        if self._is_connection_healthy():
            return
        async with self._connection_lock:
            if not self._is_connection_healthy():
                logger.debug('No healthy WebSocket connection; establishing new one')
                await self._establish_new_connection()

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key