kopia lustrzana https://github.com/Yakifo/amqtt
catch Exceptions instead of BaseExceptions
rodzic
5d74f1a8cd
commit
b1ce65057a
|
@ -165,8 +165,8 @@ class MQTTClient:
|
||||||
return await self._do_connect()
|
return await self._do_connect()
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
raise
|
raise
|
||||||
except BaseException as be:
|
except Exception as e:
|
||||||
self.logger.warning("Connection failed: %r" % be)
|
self.logger.warning("Connection failed: %r" % e)
|
||||||
auto_reconnect = self.config.get("auto_reconnect", False)
|
auto_reconnect = self.config.get("auto_reconnect", False)
|
||||||
if not auto_reconnect:
|
if not auto_reconnect:
|
||||||
raise
|
raise
|
||||||
|
@ -237,13 +237,13 @@ class MQTTClient:
|
||||||
return await self._do_connect()
|
return await self._do_connect()
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
raise
|
raise
|
||||||
except BaseException as e:
|
except Exception as e:
|
||||||
self.logger.warning("Reconnection attempt failed: %r" % e)
|
self.logger.warning("Reconnection attempt failed: %r" % e)
|
||||||
if reconnect_retries >= 0 and nb_attempt > reconnect_retries:
|
if reconnect_retries >= 0 and nb_attempt > reconnect_retries:
|
||||||
self.logger.error(
|
self.logger.error(
|
||||||
"Maximum number of connection attempts reached. Reconnection aborted"
|
"Maximum number of connection attempts reached. Reconnection aborted"
|
||||||
)
|
)
|
||||||
raise ConnectException("Too many connection attempts failed")
|
raise ConnectException("Too many connection attempts failed") from e
|
||||||
exp = 2 ** nb_attempt
|
exp = 2 ** nb_attempt
|
||||||
delay = exp if exp < reconnect_max_interval else reconnect_max_interval
|
delay = exp if exp < reconnect_max_interval else reconnect_max_interval
|
||||||
self.logger.debug("Waiting %d second before next attempt" % delay)
|
self.logger.debug("Waiting %d second before next attempt" % delay)
|
||||||
|
|
|
@ -39,7 +39,8 @@ class ClientProtocolHandler(ProtocolHandler):
|
||||||
try:
|
try:
|
||||||
self.logger.debug("Cancel ping task")
|
self.logger.debug("Cancel ping task")
|
||||||
self._ping_task.cancel()
|
self._ping_task.cancel()
|
||||||
except BaseException:
|
except Exception as e:
|
||||||
|
self.logger.debug("Silenced exception %r", e)
|
||||||
pass
|
pass
|
||||||
if not self._disconnect_waiter.done():
|
if not self._disconnect_waiter.done():
|
||||||
self._disconnect_waiter.cancel()
|
self._disconnect_waiter.cancel()
|
||||||
|
@ -90,8 +91,8 @@ class ClientProtocolHandler(ProtocolHandler):
|
||||||
if not self._ping_task:
|
if not self._ping_task:
|
||||||
self.logger.debug("Scheduling Ping")
|
self.logger.debug("Scheduling Ping")
|
||||||
self._ping_task = asyncio.ensure_future(self.mqtt_ping())
|
self._ping_task = asyncio.ensure_future(self.mqtt_ping())
|
||||||
except BaseException as be:
|
except Exception as e:
|
||||||
self.logger.debug("Exception ignored in ping task: %r" % be)
|
self.logger.debug("Exception ignored in ping task: %r" % e)
|
||||||
|
|
||||||
def handle_read_timeout(self):
|
def handle_read_timeout(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -59,7 +59,7 @@ EVENT_MQTT_PACKET_SENT = "mqtt_packet_sent"
|
||||||
EVENT_MQTT_PACKET_RECEIVED = "mqtt_packet_received"
|
EVENT_MQTT_PACKET_RECEIVED = "mqtt_packet_received"
|
||||||
|
|
||||||
|
|
||||||
class ProtocolHandlerException(BaseException):
|
class ProtocolHandlerException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -524,7 +524,7 @@ class ProtocolHandler:
|
||||||
self.handle_read_timeout()
|
self.handle_read_timeout()
|
||||||
except NoDataException:
|
except NoDataException:
|
||||||
self.logger.debug("%s No data available" % self.session.client_id)
|
self.logger.debug("%s No data available" % self.session.client_id)
|
||||||
except BaseException as e:
|
except Exception as e:
|
||||||
self.logger.warning(
|
self.logger.warning(
|
||||||
"%s Unhandled exception in reader coro: %r"
|
"%s Unhandled exception in reader coro: %r"
|
||||||
% (type(self).__name__, e)
|
% (type(self).__name__, e)
|
||||||
|
@ -554,7 +554,7 @@ class ProtocolHandler:
|
||||||
await self.handle_connection_closed()
|
await self.handle_connection_closed()
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
raise
|
raise
|
||||||
except BaseException as e:
|
except Exception as e:
|
||||||
self.logger.warning("Unhandled exception: %s" % e)
|
self.logger.warning("Unhandled exception: %s" % e)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue