Skip to content

Commit c35316a

Browse files
authored
Merge pull request #119 from vladak/connect_retries
make connect retries configurable
2 parents c993271 + a47b298 commit c35316a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

adafruit_minimqtt/adafruit_minimqtt.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class MQTT:
134134
:param bool use_binary_mode: Messages are passed as bytearray instead of string to callbacks.
135135
:param int socket_timeout: How often to check socket state for read/write/connect operations,
136136
in seconds.
137+
:param int connect_retries: How many times to try to connect to broker before giving up.
137138
138139
"""
139140

@@ -152,6 +153,7 @@ def __init__(
152153
ssl_context=None,
153154
use_binary_mode=False,
154155
socket_timeout=1,
156+
connect_retries=5,
155157
):
156158

157159
self._socket_pool = socket_pool
@@ -166,6 +168,7 @@ def __init__(
166168
)
167169
self._socket_timeout = socket_timeout
168170
self._recv_timeout = recv_timeout
171+
self._connect_retries = connect_retries
169172

170173
self.keep_alive = keep_alive
171174
self._user_data = None
@@ -267,7 +270,7 @@ def _get_connect_socket(self, host, port, *, timeout=1):
267270
sock = None
268271
retry_count = 0
269272
last_exception = None
270-
while retry_count < 5 and sock is None:
273+
while retry_count < self._connect_retries and sock is None:
271274
retry_count += 1
272275

273276
try:

0 commit comments

Comments
 (0)