def ws_loop(wsapi, message, snapshot, on_message, on_error=None,
timeout=_DEFAULT_TIMEOUT):
"""Instance trace loop."""
ws_conn = None
since = 0
while True:
apis = context.GLOBAL.ws_api(wsapi)
for api in apis:
try:
_LOGGER.debug('Connecting to %s, [timeout: %s]', api, timeout)
ws_conn = ws_client.create_connection(api, timeout=timeout)
_LOGGER.debug('Connected.')
return _ws_events(ws_conn, message, snapshot, since,
on_message, on_error)
except ws_client.WebSocketTimeoutException as to_err:
_LOGGER.debug('Connection timeout: %s, %s', api, str(to_err))
continue
except ws_client.WebSocketProxyException as proxy_err:
_LOGGER.debug('Websocket connection error: %s, %s', api,
str(proxy_err))
continue
except socket.error:
_LOGGER.debug('Connection failed: %s', api)
continue
except _RetryError as retry_err:
since = retry_err.since
if not ws_conn:
raise WSConnectionError()
评论列表
文章目录