Skip to content

Commit

Permalink
Merge pull request #119 from vladak/connect_retries
Browse files Browse the repository at this point in the history
make connect retries configurable
  • Loading branch information
tekktrik authored Aug 31, 2022
2 parents c993271 + a47b298 commit c35316a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion adafruit_minimqtt/adafruit_minimqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class MQTT:
:param bool use_binary_mode: Messages are passed as bytearray instead of string to callbacks.
:param int socket_timeout: How often to check socket state for read/write/connect operations,
in seconds.
:param int connect_retries: How many times to try to connect to broker before giving up.
"""

Expand All @@ -152,6 +153,7 @@ def __init__(
ssl_context=None,
use_binary_mode=False,
socket_timeout=1,
connect_retries=5,
):

self._socket_pool = socket_pool
Expand All @@ -166,6 +168,7 @@ def __init__(
)
self._socket_timeout = socket_timeout
self._recv_timeout = recv_timeout
self._connect_retries = connect_retries

self.keep_alive = keep_alive
self._user_data = None
Expand Down Expand Up @@ -267,7 +270,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
sock = None
retry_count = 0
last_exception = None
while retry_count < 5 and sock is None:
while retry_count < self._connect_retries and sock is None:
retry_count += 1

try:
Expand Down

0 comments on commit c35316a

Please sign in to comment.