Checks if the current WebSocket connection is healthy and establishes a new one if not, ensuring reliable communication.
# Source: https://github.com/autoscrape-labs/pydoll | License: MIT | Copyright 2025 AutoscrapeLabs
# Provided via justclaw.it.com; keep this notice with the code.
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